@
topic
The first question that Italy is a total of four kinds of numbers {0,1,2,3} for selection, asked how many sequences of length n all m to satisfy the condition, that each of said interval [L, R] inner there must be exactly x different numbers.
The second question question is intended for selection numbers 10, asked how many sequences of length n all m to satisfy the condition, that each said interval the product of [L, R] 9 numbers must be a multiple of.
Resolve
- hdu6578
- \ (dp [t] [i ] [j] [k] \) shows a front fill out \ (T \) positions, { \ (0,1,2,3 \) } appearing in the last figures appearing position after sorting \ (t, i, j, k (t \ gt i \ gt j \ gt k) \) number scheme. \ (0 \) represents the number does not appear.
- Enumerate four kinds of transfer:
- Fill \ (t-1 \) digital positions: \ (DP [T] [I] [J] [K] \)
- Fill \ (I \) digital positions: \ (DP [T] [T-. 1] [J] [K] \)
- Fill \ (J \) digital positions: \ (DP [T] [T-. 1] [I] [K] \)
- Fill \ (K \) digital positions: \ (DP [T] [T-. 1] [I] [J] \)
- But not all transfers are valid, so to enumerate restrictions, the illegal transfer pass out
- Enumerate all end in \ (t \) restriction point, the illegal transfer of \ (dp \) value of zero.
- Time complexity: \ (O (n-^. 4) \) , the complexity of the array of space-optimized scroll: \ (O (n-^. 3) \)
- 2019 Hunan Race D title Modulo Nine
- On whether the product is a multiple of 9, there are only three types of numbers, 0 and 9 show two 3,3 and 6 represent a 3, the other represents zero 3
- \ (dp [t] [i ] [j] \) shows a front fill out \ (T \) position, in the last 3 \ (I \) , the penultimate 3 \ (J \) Number Scheme .
- Enumerate three kinds of transfer:
- Fill \ (or 0. 9 \) : \ (DP [T] [T] [T] \)
- Fill \ (or 3. 6 \) : \ (DP [T] [T] [I] \)
- Other figures fill: \ (DP [T] [I] [J] \)
- But not all transfers are valid, so to enumerate restrictions, the illegal transfer pass out
- Enumerate all end in \ (t \) restriction point, the illegal transfer of \ (dp \) value of zero.
- Time complexity: \ (O (n-^. 3) \) complexity, an array of space-optimized scroll: \ (O (^ n-2) \)
Thinking exactly the same two questions, it is a classic dp.
AC_Code
hdu6578
const int mod = 998244353;
const int MXN = 1e5 + 7;
const int MXE = 2e5 + 7;
int n, m, c;
vector<pii> mp[MXN];
LL dp[2][101][101][101];
void get_dp() {
dp[c][0][0][0] = 1;
for(int t = 1; t <= n; ++t) {
c ^= 1;
for(int i = 0; i <= t; ++i) for(int j = 0; j <= i; ++j) for(int k = 0; k <= j; ++k) dp[c][i][j][k] = 0;
for(int i = 0; i < t; ++i) for(int j = 0; j <= i; ++j) for(int k = 0; k <= j; ++k) {
if((i != j && j != k) || k == 0) {
dp[c][i][j][k] = (dp[c][i][j][k] + dp[c ^ 1][i][j][k]) % mod;
dp[c][t - 1][j][k] = (dp[c][t - 1][j][k] + dp[c ^ 1][i][j][k]) % mod;
dp[c][t - 1][i][j] = (dp[c][t - 1][i][j] + dp[c ^ 1][i][j][k]) % mod;
dp[c][t - 1][i][k] = (dp[c][t - 1][i][k] + dp[c ^ 1][i][j][k]) % mod;
}
}
for(int h = 0; h < (int)mp[t].size(); ++h) {
int l = mp[t][h].fi, x = mp[t][h].se;
for(int i = 0; i < t; ++i) for(int j = 0; j <= i; ++j) for(int k = 0; k <= j; ++k) {
int cnt = 1;
if(i >= l) ++ cnt;
if(j >= l) ++ cnt;
if(k >= l) ++ cnt;
if(cnt != x) dp[c][i][j][k] = 0;
}
}
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("/home/cwolf9/CLionProjects/ccc/in.txt", "r", stdin);
//freopen("/home/cwolf9/CLionProjects/ccc/out.txt", "w", stdout);
#endif
int tim = read();
while(tim --) {
n = read(), m = read();
for(int i = 1, a, b, c; i <= m; ++i) {
a = read(), b = read(), c = read();
mp[b].eb(mk(a, c));
}
get_dp();
LL ans = 0;
for(int i = 0; i < n; ++i)
for(int j = 0; j <= i; ++j)
for(int k = 0; k <= j; ++k) if((i != j && j != k) || k == 0) ans = (ans + dp[c][i][j][k]) % mod;
printf("%lld\n", (ans+mod)%mod);
}
#ifndef ONLINE_JUDGE
cout << "time cost:" << clock() << "ms" << endl;
#endif
return 0;
}
2019省赛D
const int mod = 1e9 + 7;
const int MXN = 1e5 + 7;
const int MXE = 2e5 + 7;
int n, m, c;
int mp[MXN];
LL dp[2][101][101];
void get_dp() {
clr(dp, 0);
dp[c][0][0] = 1;
for(int t = 1; t <= n; ++t) {
c ^= 1;
for(int i = 0; i <= t; ++i) for(int j = 0; j <= i; ++j) dp[c][i][j] = 0;
for(int i = 0; i <= t; ++i) {
for(int j = 0; j <= i; ++j) {
dp[c][i][j] = (dp[c][i][j] + dp[c^1][i][j] * 6) % mod;
dp[c][t][i] = (dp[c][t][i] + dp[c^1][i][j] * 2) % mod;
dp[c][t][t] = (dp[c][t][t] + dp[c^1][i][j] * 2) % mod;
}
}
if(mp[t] == -1) continue;
for(int i = 0; i <= t; ++i) {
for(int j = 0; j <= i; ++j) {
if(i < mp[t] || j < mp[t]) dp[c][i][j] = 0;
}
}
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("/home/cwolf9/CLionProjects/ccc/in.txt", "r", stdin);
//freopen("/home/cwolf9/CLionProjects/ccc/out.txt", "w", stdout);
#endif
int tim = 1;
while(~scanf("%d%d", &n, &m)) {
for(int i = 1; i <= n; ++i) mp[i] = - 1;
for(int i = 1, a, b; i <= m; ++i) {
a = read(), b = read();
mp[b] = big(mp[b], a);
}
get_dp();
LL ans = 0;
for(int i = 0; i <= n; ++i) for(int j = 0; j <= i; ++j) ans = (ans + dp[c][i][j]) % mod;
printf("%lld\n", (ans + mod) % mod);
}
#ifndef ONLINE_JUDGE
cout << "time cost:" << clock() << "ms" << endl;
#endif
return 0;
}