http://hihocoder.com/problemset/problem/1454
调了好长时间,谜之WA。。。
等我以后学好dp再来看为什么吧,先弃坑(╯‵□′)╯︵┻━┻
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int pp = 998244353;
const int N = 503;
int f[N][N], g[N][N], n;
char A[N], B[N];
int main() {
// freopen("B.in", "r", stdin);
scanf("%d", &n);
scanf("%s%s", A + 1, B + 1);
for (int i = 1; i <= n; ++i) {
if (A[i] == '1') continue;
g[i][i] = f[i][i] = 1;
}
if (B[1] == '1') {puts("0"); return 0;}
for (int p = 2; p <= n; ++p)
for (int j = p, i = 1; j <= n; ++j, ++i) {
if (A[i] != '0') f[i][j] = g[i + 1][j];
if (A[i] != '0') {
if (B[i] == '0') g[i][j] = f[i][j];
else {
if (B[i] == '?') g[i][j] = f[i][j];
for (int k = i; k < j; ++k)
g[i][j] = (g[i][j] + ((int) (1ll * f[i][k] * g[k + 1][j] % pp))) % pp;
}
} else {
if (B[i] != '0') g[i][j] = g[i + 1][j];
}
}
printf("%d
", f[1][n]);
return 0;
}