제출 #957761

#제출 시각아이디문제언어결과실행 시간메모리
957761ArashJafariyanZapina (COCI20_zapina)C++17
110 / 110
83 ms1468 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...