QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#706285 | #6698. Flipping Game | futarian# | AC ✓ | 169ms | 3956kb | C++14 | 1.5kb | 2024-11-03 10:01:12 | 2024-11-03 10:01:13 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
const int Len = 105 , mod = 998244353;
inline void Mod(int &x){if(x >= mod) x -= mod;}
int ret,n,k,m,mr[Len][Len],dp[Len],pd[Len],C[Len][Len];
char s[105],ss[105];
/*mr(i,j) i 个不同的到 j 个不同的方案数
i 不同 n - i 不相同
枚举每次选择 k 个不同的位置变化,还需要选择 l = j - (i - k) 个位置进行变化,判断 k + l == m 即可
*/
signed main()
{
int T;scanf("%d",&T);
while(T --)
{
scanf("%d %d %d",&n,&k,&m);ret = 0;
scanf("%s",s + 1);
scanf("%s",ss + 1);
for(int i = 1 ; i <= n ; i ++) ret += (s[i] != ss[i]);
for(int i = 0 ; i <= n ; i ++) C[i][0] = 1;
for(int i = 1 ; i <= n ; i ++)
for(int j = 1 ; j <= i ; j ++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) , Mod(C[i][j]);
for(int i = 0 ; i <= n ; i ++)
for(int j = 0 ; j <= n ; j ++)
{
mr[i][j] = 0;
for(int k = 0 , l ; k <= i ; k ++)
{
l = j - (i - k);
if(l < 0) continue;
if(l + k != m) continue;
//if(i == 2 && j == 0) printf("???%d %d %d %d\n",i,j,k,l);
mr[i][j] += 1ll * C[i][k] * C[n - i][l] % mod;
Mod(mr[i][j]);
}
//printf("???%d %d %d\n",i,j,mr[i][j]);
}
for(int i = 0 ; i <= n ; i ++) dp[i] = pd[i] = 0;
dp[ret] = 1;
while(k --)
{
for(int i = 0 ; i <= n ; i ++) pd[i] = dp[i] , dp[i] = 0;
for(int i = 0 ; i <= n ; i ++)
for(int j = 0 ; j <= n ; j ++) dp[i] += 1ll * pd[j] * mr[j][i] % mod , Mod(dp[i]);
}
printf("%d\n",dp[0]);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3876kb
input:
3 3 2 1 001 100 3 1 2 001 100 3 3 2 001 100
output:
2 1 7
result:
ok 3 number(s): "2 1 7"
Test #2:
score: 0
Accepted
time: 169ms
memory: 3956kb
input:
1000 8 50 2 11111001 01100001 13 4 5 0010011001101 0000001010010 15 58 12 011111110110100 011010000101000 15 30 2 000101100111101 100010100110000 16 99 15 0111011010111101 1000100101011100 7 73 1 0010010 1010111 1 45 1 1 1 15 64 4 111000001000100 111000110011011 13 16 6 0000001101000 0101001010111 5...
output:
0 0 0 0 0 565123576 0 671397628 866048220 0 0 0 934159397 0 0 0 657964873 0 0 0 297620792 518284447 16636231 1 294524820 259008109 0 0 0 0 0 0 990349196 899244686 0 0 497963164 0 49814547 0 0 0 0 0 529815127 411739397 562040211 0 0 0 0 0 0 0 531433326 0 77531359 703399699 0 0 0 1 0 896329183 0 0 0 0...
result:
ok 1000 numbers