Submission #1914374
Source Code Expand
#include <iostream> using namespace std; const int mod = 1000000007; int N, M, dp[309][309][309]; bool vis[309][309][309]; int solve(int t, int terr, int half) { if (t == M) return (terr == N ? 1 : 0); if (vis[t][terr][half]) return dp[t][terr][half]; int ret = 0; if (half == 0) { ret = (ret + 1LL * solve(t + 1, terr, half) * terr) % mod; if(terr < N) ret = (ret + solve(t + 1, terr, half + 1)) % mod; } else { ret = (ret + 1LL * solve(t + 1, terr, half) * half) % mod; ret = (ret + 1LL * solve(t + 1, terr + half, 0) * terr) % mod; if(terr + half < N) ret = (ret + 1LL * solve(t + 1, terr, half + 1)) % mod; } vis[t][terr][half] = true; dp[t][terr][half] = ret; return ret; } int main() { cin >> N >> M; int ret = solve(0, 1, 0); for (int i = 1; i < N; i++) ret = 1LL * ret * i % mod; cout << ret << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Road of the King |
User | square1001 |
Language | C++14 (GCC 5.4.1) |
Score | 1000 |
Code Size | 872 Byte |
Status | AC |
Exec Time | 157 ms |
Memory | 139648 KB |
Judge Result
Set Name | sample | all | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1000 / 1000 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt, sample-03.txt |
all | sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, sample-01.txt, sample-02.txt, sample-03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 2 ms | 2304 KB |
01-02.txt | AC | 2 ms | 2304 KB |
01-03.txt | AC | 28 ms | 139648 KB |
01-04.txt | AC | 2 ms | 2304 KB |
01-05.txt | AC | 28 ms | 139648 KB |
01-06.txt | AC | 54 ms | 139648 KB |
01-07.txt | AC | 156 ms | 139648 KB |
01-08.txt | AC | 157 ms | 139648 KB |
01-09.txt | AC | 157 ms | 139648 KB |
01-10.txt | AC | 157 ms | 139648 KB |
sample-01.txt | AC | 2 ms | 2304 KB |
sample-02.txt | AC | 92 ms | 139648 KB |
sample-03.txt | AC | 30 ms | 70016 KB |