-
Notifications
You must be signed in to change notification settings - Fork 0
/
7143_RoomAssignment.cc
136 lines (113 loc) · 2.39 KB
/
7143_RoomAssignment.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
*
* Author : fcbruce <fcbruce8964@gmail.com>
*
* Time : Fri 09 Oct 2015 03:20:54 PM CST
*
*/
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#ifdef _WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
const double PI = acos(-1.0);
const double eps = 1e-10;
typedef long long LL;
typedef int itn;
const int maxn = 100007;
const int maxm = 0;
const long long mod = 1000000007ll;
long long dp[17][107];
long long c[17];
long long rest[17];
long long p[maxn];
long long inv[maxn];
long long gcd(long long a, long long b, long long &x, long long &y)
{
if (b == 0)
{
x = 1; y = 0;
return a;
}
else
{
long long d = gcd(b, a % b, y, x);
y -= x * (a / b);
return d;
}
}
long long inver(long long x)
{
long long a, b;
gcd(x, mod, a, b);
a %= mod; a += mod; a %= mod;
return a;
}
inline long long com(int i, int j)
{
return (p[i] * inv[j] % mod) * inv[i - j] % mod;
}
int main()
{
#ifdef FCBRUCE
freopen("/home/fcbruce/code/t", "r", stdin);
#endif // FCBRUCE
int T_T, __ = 0;
scanf("%d", &T_T);
p[0] = 1;
for (int i = 1; i < maxn; i++) p[i] = p[i - 1] * i % mod;
for (int i = 0; i < maxn; i++) inv[i] = inver(p[i]);
while (T_T--)
{
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= m; i++) scanf(lld, c + i);
int rest = n;
c[0] = 0;
memset(dp, 0, sizeof dp);
dp[0][k] = 1;
for (int i = 0; i < m; i++)
{
rest -= c[i];
for (int j = 0; j <= k; j++)
{
if (rest < 2 * j) break;
for (int x = 0; x <= j; x++)
{
for (int y = 0; y <= j - x; y++) if (c[i + 1] - 2 * x - y >= 0 && rest - 2 * j >= c[i + 1] - 2 * x - y)
{
long long add = dp[i][j] * com(j, x);
add %= mod;
add *= com(j - x, y);
add %= mod;
add *= com(rest - 2 * j, c[i + 1] - 2 * x - y);
add %= mod;
dp[i + 1][j - x - y] += add;
dp[i + 1][j - x - y] %= mod;
}
}
}
}
printf("Case #%d: " lld "\n", ++__, dp[m][0]);
}
return 0;
}