hdu 4055(dp)
3487 단어 ACM-DP
#include
#include
#define ll __int64
const int N = 1005;
const ll MOD = 1000000007;
char str[N];
ll f[N][N], sum[N];
int main() {
while (scanf("%s", str + 1) != EOF) {
int len = strlen(str + 1);
memset(f, 0, sizeof(f));
f[0][1] = 1;
for (int i = 1; i <= len; i++) {
sum[0] = 0;
for (int j = 1; j <= i + 1; j++)
sum[j] = sum[j - 1] + f[i - 1][j];
for (int j = 1; j <= i + 1; j++) {
if (str[i] == 'I' || str[i] == '?')
f[i][j] = (f[i][j] + sum[j - 1]) % MOD;
if (str[i] == 'D' || str[i] == '?')
f[i][j] = (f[i][j] + sum[i] - sum[j - 1]) % MOD;
}
}
ll res = 0;
for (int i = 1; i <= len + 1; i++)
res = (res + f[len][i]) % MOD;
printf("%I64d
", res);
}
return 0;
}