QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#612058 | #6698. Flipping Game | kevinyang# | AC ✓ | 146ms | 34792kb | C++14 | 1.5kb | 2024-10-05 03:23:27 | 2024-10-05 03:23:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
vector<int>fact(2000010);
vector<int>inv(2000010);
int modpow(int x, int y) {
return !y?1:((y % 2 ? x : 1) * modpow((x * x) % mod, y / 2)) % mod;
}
int choose(int x, int y){
if(y>x)return 0;
return (fact[x]*inv[y]%mod)*inv[x-y]%mod;
}
int permute(int x, int y){
if(y>x)return 0;
return (fact[x]*inv[x-y])%mod;
}
void precalc(){
fact[0] = 1; inv[0] = 1;
for(int i = 1; i<=2000000; i++){
fact[i] = fact[i-1]*i%mod;
}
inv[2000000] = modpow(fact[2000000],mod-2);
for(int i = 1999999; i>0; i--){
inv[i] = inv[i+1]*(i+1)%mod;
}
}
signed main() {
cin.tie(0)->sync_with_stdio(0); precalc();
int t;
cin >> t;
while(t--){
int n,k,m;
cin >> n >> k >> m;
string s,t;
cin >> s >> t;
int d = 0;
for(int i = 0; i<n; i++){
if(s[i]!=t[i]){
d++;
}
}
vector<vector<int>>dp(k+1,vector<int>(n+1));
dp[0][0] = 1;
for(int a = 1; a<=k; a++){
for(int i = 0; i<=n; i++){
for(int j = 0; j<=min(i,m); j++){
int p = i-j + (m-j);
dp[a][i]+=dp[a-1][p] * choose(i,j)%mod * choose(n-i,m-j)%mod;
dp[a][i]%=mod;
}
}
}
cout << dp[k][d] << '\n';
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 15ms
memory: 34240kb
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: 146ms
memory: 34792kb
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