-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathUVa11982.cc
61 lines (56 loc) · 1.45 KB
/
UVa11982.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// UVa11982 Fantasy Cricket
// 陈锋
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>
using namespace std;
#define _for(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define _rep(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define _zero(D) memset((D), 0, sizeof(D))
#define _init(D, v) memset((D), (v), sizeof(D))
#define _ri1(x) scanf("%d", &(x))
#define _ri2(x, y) scanf("%d%d", &(x), &(y))
#define _ri3(x, y, z) scanf("%d%d%d", &(x), &(y), &(z))
#define _ri4(a, b, c, d) scanf("%d%d%d%d", &(a), &(b), &(c), &(d))
typedef long long LL;
const LL M = 1000000007;
const int MAXN = 1000 + 4;
LL D[MAXN][MAXN];
void add_mod(LL& x, LL y) { x = (x + (y % M)) % M; }
LL solve(const char* S) {
int N = strlen(S + 1);
if (N == 0) return 1;
_zero(D);
D[0][0] = 1;
_rep(i, 1, N) _rep(j, 0, i) {
LL& d = D[i][j];
if (S[i] == 'D')
add_mod(d, D[i - 1][j] * j + D[i - 1][j + 1] * (j + 1) * (j + 1));
else if (S[i] == 'U')
add_mod(d, D[i - 1][j - 1] + D[i - 1][j] * j);
else
d = D[i - 1][j];
}
return D[N][0];
}
char S[MAXN];
int main() {
int T;
_ri1(T);
_rep(t, 1, T) {
scanf("%s", S + 1);
printf("Case %d: %lld\n", t, solve(S));
}
return 0;
}
// 22149206 11982 Fantasy Cricket Accepted C++11 0.210 2018-10-18 14:51:43