2019 Multi-University Training Contest 1 题解

1001 - Blank

$ Dp $. Restrictions to the number of species, some number that appears in the interval, in fact, relatively easy to think of a classic title, is a sequence as well as many groups asking, asking each the number of digits within a range of different types of queries, the question of a press the right endpoint approach is to ask ascending order, then scan line, the position of each number that appears at the latest maintenance with a segment tree. This kind of problem because the numbers themselves rarely, only four, so we can use $ dp [i] [a] [b] [c] [d] $ ago to $ i $ th position the four digit recent position program numbers are $ a, b, c, d $, but this memory is not enough, in fact, has a dimension is omitted, because $ a, b, c, d $ exactly one is $ I $, and in fact we do not care about which specific numbers are in a position, therefore, we can simplify the state, with $ dp [i] [a] [b] [c] $ $ i $ a front position, with the exception of the $ i $ th digital outer position, respectively, in the other three digital numbers $ a, b, c $ scheme where $ a \ leq b \ leq c $, transfer comparison clearly not be listed here.

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<vector>
 4 const int mod=998244353;
 5 inline void upd(int &a,int x) {
 6     a+=x;
 7     if(a>=mod) a-=mod;
 8 }
 9 const int N=101;
10 int n,m,dp[2][N][N][N];
11 typedef std::pair<int,int> P;
12 std::vector<P> g[N];
13 int main() {
14     int T;
15     scanf("%d",&T);
16     while(T--) {
17         scanf("%d%d",&n,&m);
18         for(int i=1;i<=n;i++) g[i].clear();
19         for(int l,r,x;m--;) {
20             scanf("%d%d%d",&l,&r,&x);
21             g[r].push_back(P(l,x));
22         }
23         dp[1][0][0][0]=4;
24         int ans=0;
25         for(int i=1;i<=n;i++) {
26             int t=i&1;
27             if(i<n) for(int x=0;x<=i;++x) for(int y=x;y<=i;y++) for(int z=y;z<=i;z++) dp[t^1][x][y][z]=0;
28             for(int x=0;x<i;++x) for(int y=x;y<i;y++) for(int z=y;z<i;z++) if(dp[t][x][y][z]) {
29                 bool f=true;
30                 for(auto &c:g[i]) {
31                     int num=1;
32                     if(x>=c.first) num+=3;
33                     else if(y>=c.first) num+=2;
34                     else if(z>=c.first) num++;
35                     if(num!=c.second) {
36                         f=false;
37                         break;
38                     }
39                 }
40                 if(!f) {
41                     dp[t][x][y][z]=0;
42                     continue;
43                 }
44                 if(i==n) upd(ans,dp[t][x][y][z]);
45                 else {
46                     upd(dp[t^1][x][y][z],dp[t][x][y][z]);
47                     upd(dp[t^1][y][z][i],dp[t][x][y][z]);
48                     upd(dp[t^1][x][z][i],dp[t][x][y][z]);
49                     upd(dp[t^1][x][y][i],dp[t][x][y][z]);
50                 }
51             }
52         }
53         printf("%d\n",ans);
54     }
55     return 0;
56 }
View Code

 

1012 - Sequence

$ NTT $. If we let $ f = \ sum_ {i = 1} ^ n a_ix ^ i $, $ g (c) = \ sum_ {i = 0} x ^ {ci} $, then after $ m $ operations, the final sequence of $ I $ item is $ f \ prod_ {i = 1} factor ^ mg (c_i) $ a $ x ^ i $ a. We let $ h = \ prod_ {i = 1} ^ mg (c_i) $, it can be seen, the sequence of operations is no effect on the results, whereby we can calculate the value of the classification by the $ $ C_i. We first consider the $ c_i = 1. $, this time with a $ g (1) = \ sum_ {i = 0} x ^ i $, Operating the $ c_i = 1 $ are $ k $ a, then clearly there is $ g (1) ^ k = \ sum_ {i = 0} C_ {i + k-1} ^ {i} x ^ i $, because it is equivalent to calculating the difference between the $ I $-free of items into $ k there are several programs $ a difference in the box. For $ c_i 2 $ and the case = $ c_i = 3 $, in fact, the calculation is the same, not repeat them here, we use the last $ NTT $ accelerated multiplication can be.

Guess you like

Origin www.cnblogs.com/Onlymyheart/p/11235285.html