I am not very familiar with such questions .. Injury, look at others
View code
1 # Include <stdio. h>
2 # Include < String . H>
3 # Define Maxn 1010
4 Int DP [maxn] [maxn];
5 Int Sum [maxn] [maxn];
6 Const Int MoD = 1000000007 ;
7 Int Main ()
8 {
9 Int I, J;
10 Char S [maxn];
11 While (Scanf ( " % S " , S )! = EOF)
12 {
13 Int N = strlen (s );
14 Memset (DP, 0 , Sizeof (DP ));
15 Memset (sum, 0 , Sizeof (SUM ));
16 For (I = 1 ; I <= N +1 ; I ++) sum [ 0 ] [I] = 1 ;
17 For (I = 1 ; I <= N; I ++)
18 {
19 For (J = 1 ; J <= I + 1 ; J ++)
20 {
21 If (S [I- 1 ] = ' I ' | S [I- 1 ] = ' ? ' )
22 {
23 DP [I] [J] + = sum [I- 1 ] [J- 1 ];
24 }
25 If (S [I- 1 ] = ' D ' | S [I- 1 ] = ' ? ' )
26 {
27 DP [I] [J] + = (sum [I-1 ] [I]-sum [I- 1 ] [J- 1 ]);
28 DP [I] [J] = (DP [I] [J] + mod) % MOD;
29 }
30 Sum [I] [J] + = (sum [I] [J- 1 ] + Dp [I] [J]) % MOD;
31 }
32 }
33 Int Ans = 0 ;
34 For (I = 0 ; I <= N + 1 ; I ++)
35 Ans = (ANS + dp [N] [I]) % MOD;
36 Printf ( " % D \ n " , ANS );
37 }
38 Return 0 ;
39 }