比赛 20241025 评测结果 AAAAAAAAAAAAAAAA
题目名称 Pair Programming 最终得分 100
用户昵称 ┭┮﹏┭┮ 运行时间 1.093 s
代码语言 C++ 内存使用 65.18 MiB
提交时间 2024-10-25 11:41:09
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 2010;
const ll mod = 1e9+7;

ll read(){
	ll x = 0,f = 1;char c = getchar();
	for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
	for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
	return x * f;
}


int n,l1,l2;
ll f[N][N][2];
char c1[N],c2[N];


void solve(){
	n = read();
	l1 = l2 = 0;
	for(int i = 1;i <= n;i++){
		char c;cin>>c;
		if(c == '0')l1 = 0;
		if(c == '1')continue;
		else c1[++l1] = c;
	}
	for(int i = 1;i <= n;i++){
		char c;cin>>c;
		if(c == '0')l2 = 0;
		if(c == '1')continue;
		else c2[++l2] = c;
	}
	memset(f,0,sizeof f);
	f[0][0][1] = 1;
	for(int i = 0;i <= l1;i++){
		for(int j = 0;j <= l2;j++){
			if(i > 0)f[i][j][0] = (f[i-1][j][0] + f[i-1][j][1]) % mod;
			if(j > 0)f[i][j][1] = f[i][j-1][1] % mod;
			if(i > 0 && j > 0 && ((c1[i] == '+' && c2[j] != '+') || (c1[i] != '+' && c2[j] == '+')))
				f[i][j][1] = (f[i][j-1][1] + f[i][j-1][0]) % mod;
//			printf("--- %d %d %lld %lld\n",i,j,f[i][j][0],f[i][j][1]);
		}
//		printf("\n----------------------------\n");
	}
	printf("%lld\n",(f[l1][l2][0] + f[l1][l2][1]) % mod);
}

int main(){
	freopen("prob2_gold_22open.in","r",stdin);
	freopen("prob2_gold_22open.out","w",stdout);
	int t = read();
	while(t--)solve();

	return 0;

}