QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#612058#6698. Flipping Gamekevinyang#AC ✓146ms34792kbC++141.5kb2024-10-05 03:23:272024-10-05 03:23:27

Judging History

你现在查看的是最新测评结果

  • [2024-10-05 03:23:27]
  • 评测
  • 测评结果:AC
  • 用时:146ms
  • 内存:34792kb
  • [2024-10-05 03:23:27]
  • 提交

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