1 #include<stdio.h>
2 #include<string.h>
3 #define MOD 1000000007
4 int dp[1005][1005],sum[1005][1005];
5 char s[1005];
6 int main()
7 {
8 int len,i,j;
9 while (~scanf("%s",s+2))
10 {
11 len=strlen(s+2);
12 memset(dp,0,sizeof(dp));
13 memset(sum,0,sizeof(sum));
14 dp[1][1]=1; sum[1][1]=1;
15 for (i=2;i<=len+1;i++)
16 for (j=1;j<=i;j++)
17 {
18 if (s[i]=='I'||s[i]=='?') dp[i][j]=sum[i-1][j-1]%MOD;
19 if (s[i]=='D'||s[i]=='?') dp[i][j]=((sum[i-1][i-1]+MOD-sum[i-1][j-1])%MOD+dp[i][j])%MOD;
20 sum[i][j]=(sum[i][j-1]+dp[i][j])%MOD;
21 }
22 printf("%d\n",sum[len+1][len+1]);
23 }
24 }
http://acm.hdu.edu.cn/showproblem.php?pid=4055