/*
https://oj.uz/problem/view/COCI20_zapina
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"
const int N = 350;
/// dp[i][many] = the number of ways to not make anybody happy with many tasks and on prefix 1..i of programmers
const int MOD = 1e9 + 7;
int dp[1 + N][1 + N];
int comb[1 + N][1 + N];
void add (int &a, int b) {
a += b;
if (a >= MOD)
a -= MOD;
}
int main() {
ios::sync_with_stdio (false);
cin.tie (0); cout.tie (0);
int n;
cin >> n;
for (int i = 0; i <= n; i++) {
comb[i][0] = 1;
for (int j = 1; j <= i; j++)
comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % MOD;
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int many = 0; many <= n; many++) {
for (int j = 0; j <= many; j++) {
if (j == i) continue;
add (dp[i][many], 1ll * dp[i - 1][many - j] * comb[n - (many - j)][j] % MOD);
}
}
}
int ans = 1;
for (int i = 1; i <= n; i++)
ans = 1ll * ans * n % MOD;
ans -= dp[n][n];
if (ans < 0)
ans += MOD;
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
53 ms |
1144 KB |
Output is correct |
18 |
Correct |
5 ms |
504 KB |
Output is correct |
19 |
Correct |
15 ms |
760 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
70 ms |
1144 KB |
Output is correct |
22 |
Correct |
12 ms |
760 KB |
Output is correct |
23 |
Correct |
5 ms |
504 KB |
Output is correct |
24 |
Correct |
18 ms |
764 KB |
Output is correct |
25 |
Correct |
14 ms |
760 KB |
Output is correct |
26 |
Correct |
24 ms |
888 KB |
Output is correct |
27 |
Correct |
101 ms |
1272 KB |
Output is correct |
28 |
Correct |
98 ms |
1268 KB |
Output is correct |
29 |
Correct |
98 ms |
1272 KB |
Output is correct |
30 |
Correct |
100 ms |
1272 KB |
Output is correct |
31 |
Correct |
99 ms |
1272 KB |
Output is correct |
32 |
Correct |
101 ms |
1144 KB |
Output is correct |
33 |
Correct |
101 ms |
1272 KB |
Output is correct |
34 |
Correct |
105 ms |
1272 KB |
Output is correct |
35 |
Correct |
106 ms |
1248 KB |
Output is correct |
36 |
Correct |
108 ms |
1272 KB |
Output is correct |
37 |
Correct |
104 ms |
1272 KB |
Output is correct |