Little Sub loves playing the game Flip Me Please. In the game, lights, numbered from 1 to , are connected separately to switches. The lights may be either on or off initially, and pressing the -th switch will change the -th light to its opposite status (that is to say, if the -th light is on, it will be off after the -th switch is pressed, and vice versa).
The game is composed of exactly rounds, and in each round, the player must press exactly different switches. The goal of the game is to change the lights into their target status when the game ends.
Little Sub has just come across a very hard challenge and he cannot solve it. As his friend, it's your responsibility to find out how many solutions there are to solve the challenge and tell him the answer modulo 998244353.
We consider two solutions to be different if there exist two integers and such that , and the -th switch is pressed during the -th round of the first solution while it is not pressed during the -th round of the second solution, or vice versa.
Input
There are multiple test cases. The first line of the input contains an integer (about 1000), indicating the number of test cases. For each test case:
The first line contains three integers , , (, ).
The second line contains a string () consisting of only '0' and '1', indicating the initial status of the lights. If the -th character is '1', the -th light is initially on; If the -th character is '0', the -th light is initially off.
The third line contains a string () consisting of only '0' and '1', indicating the target status of the lights. If the -th character is '1', the -th light must be on at the end of the game; If the -th character is '0', the -th light must be off at the end of the game.
It is guaranteed that there won't be more than 100 test cases that .
Output
For each test case output one line containing one integer, indicating the answer.
Sample Input
3 3 2 1 001 100 3 1 2 001 100 3 3 2 001 100
Sample Output
2 1 7
Hint
For the first sample test case, Little Sub can press the 1st switch in the 1st round and the 3rd switch in the 2nd round; Or he can press the 3rd switch in the 1st round and the 1st switch in the 2nd round. So the answer is 2.
For the second sample test case, Little Sub can only press the 1st and the 3rd switch in the 1st and only round. So the answer is 1.
这是一个计数DP(应该是,我第一次见到这个词)
我们场上就没看出是个DP,我还在分奇偶,下来一听DP明白了...
转移方程:dp[i+1][j-l+k-l] += dp[i][j]%MOD*C(l,j)%MOD*C(k-l,n-j)%MOD; C是组合数
二维的dp,一维是第几轮,第二维是不同棋子的数目,然后会产生一个分歧,如果改变的数量>k,组合数会不正确,所以可以组合数判断,也可以加个if
#include
using namespace std;
const int maxn = 1e3+3;
typedef long long LL;
const LL MOD = 998244353;
LL fac[maxn];
LL inv[maxn];
LL C(int m,int n)
{
if(m>n)
return 0;
return fac[n]*inv[m]%MOD*inv[n-m]%MOD;
}
LL quick_MOD(LL a,LL m)
{
LL tmp=a%MOD;
LL ans=1;
while(m)
{
if(m&1)
ans=ans*tmp%MOD;
tmp=tmp*tmp%MOD;
m>>=1;
}
return ans;
}
void init()
{
fac[0]=1;
for(int i=1; i=0; i--)
inv[i]=(inv[i+1]*(i+1))%MOD;
}
LL dp[103][103];
//LL C[103][103];
//void init()
//{
// for(int i=0;i<=100;i++)
// {
// for(int j=0;j<=100;j++)
// {
// if(i == 0 || j == 0)
// C[i][j] = 1;
// else if(i == 1)
// C[i][j] = j;
// else
// {
// C[i][j] = C[i-1][j]*(j-i+1)/i;
// C[i][j] %= MOD;
//// cout<>t;
while(t--)
{
int n,m,k;
cin>>n>>m>>k;
string str1,str2;
cin>>str1>>str2;
int diff = 0;
int len = str1.size();
for(int i=0; i= k-l && k-l>=0)
{
dp[i+1][j-l+k-l] += dp[i][j]%MOD*C(l,j)%MOD*C(k-l,n-j)%MOD;
dp[i+1][j-l+k-l] %= MOD;
}
}
}
}
cout<
大概跑300-500ms