이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "debug.h"
#else
#define debug(...) 0
#endif
#define pb push_back
#define ll long long
#define i2 array<int, 2>
#define SZ(x) (int) (x).size()
const int N = 350 + 4, M = 1e9 + 7;
int power(int a, int b) {
int ret = 1;
while (b) {
if (b & 1)
ret = 1LL * ret * a % M;
b >>= 1;
a = 1LL * a * a % M;
}
return ret;
}
int n, c[N][N], dp[N][N];
void solve() {
for (int i = 0; i < N; i++) {
for (int j = 0; j <= i; j++) {
if (!j || !i)
c[i][j] = 1;
else
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % M;
}
}
cin >> n;
for (int i = 0; i < N; i++)
if (i != 1)
dp[1][i] = 1;
for (int i = 2; i < N; i++) {
for (int j = 0; j < N; j++) {
for (int k = 0; k <= j; k++) {
if (k != i) {
int add = 1LL * c[j][k] * dp[i - 1][j - k] % M;
// if (i == 2 && j == 2 && k == 0)
dp[i][j] = (dp[i][j] + add) % M;
}
}
}
}
cout << (power(n, n) - dp[n][n] + M) % M;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
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... |