Submission #1914191
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int N, M; int dp[301][301][301]; int rec(int step, int sc1, int out) { if(step == M) return (sc1 == N); if(~dp[step][sc1][out]) return (dp[step][sc1][out]); int ret = 0; if(sc1 + out + 1 <= N) { (ret += 1LL * rec(step + 1, sc1, out + 1) * (N - sc1 - out) % mod) %= mod; } if(out > 0) { (ret += 1LL * rec(step + 1, sc1, out) * out % mod) %= mod; } (ret += 1LL * rec(step + 1, sc1 + out, 0) * sc1 % mod) %= mod; return (dp[step][sc1][out] = ret); } int main() { cin >> N >> M; memset(dp, -1, sizeof(dp)); cout << rec(0, 1, 0) << endl; }
Submission Info
Submission Time | |
---|---|
Task | F - Road of the King |
User | ei13333 |
Language | C++14 (GCC 5.4.1) |
Score | 1000 |
Code Size | 671 Byte |
Status | AC |
Exec Time | 182 ms |
Memory | 106752 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 | 28 ms | 106752 KB |
01-02.txt | AC | 28 ms | 106752 KB |
01-03.txt | AC | 28 ms | 106752 KB |
01-04.txt | AC | 28 ms | 106752 KB |
01-05.txt | AC | 28 ms | 106752 KB |
01-06.txt | AC | 61 ms | 106752 KB |
01-07.txt | AC | 181 ms | 106752 KB |
01-08.txt | AC | 182 ms | 106752 KB |
01-09.txt | AC | 182 ms | 106752 KB |
01-10.txt | AC | 182 ms | 106752 KB |
sample-01.txt | AC | 28 ms | 106752 KB |
sample-02.txt | AC | 104 ms | 106752 KB |
sample-03.txt | AC | 47 ms | 106752 KB |