#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int binpow(int a, int b) {
int c = 1;
while (b) {
if (b & 1)
c = (long long)c * a % MOD;
b >>= 1;
a = (long long)a * a % MOD;
}
return c;
}
int ckn[355][355];
void init(int n) {
for (int i = 0; i <= n; ++ i) {
ckn[0][i] = 1;
for (int j = 1; j <= i; ++ j)
ckn[j][i] = (ckn[j-1][i-1] + ckn[j][i-1]) % MOD;
}
}
int n;
int un_happy() {
vector<vector<int>> dp(n+5, vector<int> (n+5, 0));
dp[0][0] = 1;
for (int i = 1; i <= n; ++ i)
for (int j = 0; j <= n; ++ j)
for (int k = 0; k <= j; ++ k)
if (k != i) {
dp[i][j] += (long long)dp[i-1][j-k] * ckn[k][j] % MOD;
dp[i][j] %= MOD;
}
return dp[n][n];
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
init(n);
cout << (binpow(n, n) - un_happy() + MOD) % MOD;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
68 ms |
988 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
16 ms |
656 KB |
Output is correct |
20 |
Correct |
1 ms |
320 KB |
Output is correct |
21 |
Correct |
89 ms |
1220 KB |
Output is correct |
22 |
Correct |
10 ms |
588 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
18 ms |
700 KB |
Output is correct |
25 |
Correct |
12 ms |
640 KB |
Output is correct |
26 |
Correct |
27 ms |
716 KB |
Output is correct |
27 |
Correct |
123 ms |
1248 KB |
Output is correct |
28 |
Correct |
125 ms |
1248 KB |
Output is correct |
29 |
Correct |
125 ms |
1276 KB |
Output is correct |
30 |
Correct |
124 ms |
1228 KB |
Output is correct |
31 |
Correct |
126 ms |
1260 KB |
Output is correct |
32 |
Correct |
132 ms |
1272 KB |
Output is correct |
33 |
Correct |
128 ms |
1272 KB |
Output is correct |
34 |
Correct |
134 ms |
1284 KB |
Output is correct |
35 |
Correct |
132 ms |
1276 KB |
Output is correct |
36 |
Correct |
141 ms |
1228 KB |
Output is correct |
37 |
Correct |
134 ms |
1292 KB |
Output is correct |