-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoding Company.cpp
More file actions
executable file
·34 lines (32 loc) · 898 Bytes
/
Copy pathCoding Company.cpp
File metadata and controls
executable file
·34 lines (32 loc) · 898 Bytes
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
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
LL n, x;
LL dp[101][52][10201]; // i - coder id; j - unfinished teams; k - penalty
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> x;
vector<int> t(n + 1);
for (int i = 1; i <= n; i++) cin >> t[i];
sort(t.begin(), t.end());
dp[0][0][5000] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= 50; j++) {
for (int k = 0; k <= 10000; k++) {
dp[i][j][k] = dp[i - 1][j][k];
dp[i][j][k] = (dp[i][j][k] + j * dp[i - 1][j][k]) % MOD;
if (j > 0) dp[i][j][k] = (dp[i][j][k] + dp[i - 1][j - 1][k + t[i]]) % MOD;
if (k - t[i] >= 0) dp[i][j][k] = (dp[i][j][k] + (j + 1) * dp[i - 1][j + 1][k - t[i]]) % MOD;
}
}
}
LL res = 0;
for (int k = 5000; k <= 5000 + x; k++) {
res = (res + dp[n][0][k]) % MOD;
}
cout << res << "\n";
return 0;
}