This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |