[2019HDU first correction Multi] [HDU 6578] [A. Blank]

Topic links: http://acm.hdu.edu.cn/showproblem.php?pid=6578

Title effect: length \ (n-\) are filled array requires \ (\ {0,1,2,3 \} \) according to any one of four numbers, there are \ (m \) limitation conditions: Interval digital several species \ ([l, r] \) appears exactly \ (x \), find the number of programs

Interpretations: f [i] [j] [k] [cur] represents the number of the last four positions occurring after sorting number \ (i, j, k, cur \) program, can transfer force, wherein a final dimensional array to scroll to save space

   For vector constraints can survive, the right end point of each cycle is determined to be a restriction for the current point

   Although four sets to \ (for \), but due to the sequential limitation, the execution times of approximately \ (\ frac {n ^ 4} {24} \), coupled with a simple operation of this problem, a small constant, substantially TLE situation does not appear

 

   But still have to Tucao a topic and people have time to set up the game good ... Sia open 3s should not have had it orz holiday algorithm

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define N 101
 4 #define mp make_pair
 5 #define MOD 998244353
 6 int T,n,m,l,r,x,f[N][N][N][2],ans;
 7 vector<pair<int,int>>d[N];
 8 void init()
 9 {
10     ans=0;
11     scanf("%d%d",&n,&m);
12     for(int i=1;i<=n;i++)
13       {
14       d[i].clear();
15       d[i].push_back(mp(i,1));
16       }
17     for(int i=1;i<=m;i++)
18       {
19       scanf("%d%d%d",&l,&r,&x);
20       d[r].push_back(mp(l,x));
21       }
22     memset(f,0,sizeof(f));
23     f[0][0][0][0]=1;
24     for(int cur=1;cur<=n;cur++)
25       {
26       int o=cur&1;
27       for(int i=0;i<=cur;i++)
28         for(int j=i;j<=cur;j++)
29           for(int k=j;k<=cur;k++)
30             f[i][j][k][o]=0;
31       for(int i=0;i<=cur;i++)
32         for(int j=i;j<=cur;j++)
33           for(int k=j;k<=cur;k++)
34             {
35             (f[j][k][cur-1][o]+=f[i][j][k][o^1])%=MOD;
36             (f[i][k][cur-1][o]+=f[i][j][k][o^1])%=MOD;
37             (f[i][j][cur-1][o]+=f[i][j][k][o^1])%=MOD;
38             (f[i][j][k][o]+=f[i][j][k][o^1])%=MOD;
39             }
40       for(int i=0;i<=cur;i++)
41         for(int j=i;j<=cur;j++)
42           for(int k=j;k<=cur;k++)
43             for(auto pi:d[cur])
44               {
45               l=pi.first,r=cur,x=pi.second;
46               if((i>=l)+(j>=l)+(k>=l)+(cur>=l)!=x)
47                 f[i][j][k][o]=0;
48               }
49       }
50     for(int i=0;i<=n;i++)
51       for(int j=i;j<=n;j++)
52         for(int k=j;k<=n;k++)
53           (ans+=f[i][j][k][n&1])%=MOD;
54     printf("%d\n",ans);
55 }
56 int main()
57 {
58     scanf("%d",&T);
59     while(T--)init();
60 }
View Code

Code to initialize the vector is not really necessary, additional push_back, writing for insurance when you go to add (although almost led TLE)

 

It turned out to be my blog in the first line of pure DP problem ...?

Guess you like

Origin www.cnblogs.com/DeaphetS/p/11229389.html