Submission #7447632


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 1000000007;
Int dp[301][301][301];
int main() {
    int N, M; cin >> N >> M;
    dp[0][1][1] = 1;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j <= N; j++) {
            for (int k = 0; k <= j; k++) {
                if (j + 1 <= N) dp[i+1][j+1][k] += dp[i][j][k] * (N - j);
                dp[i+1][j][k] += dp[i][j][k] * (j - k);
                dp[i+1][j][j] += dp[i][j][k] * k;
            }
        }
        for (int j = 0; j <= N; j++) {
            for (int k = 0; k <= j; k++) {
                dp[i+1][j][k] %= MOD;
            }
        }
    }
    cout << dp[M][N][N] << '\n';
    return 0;
}

Submission Info

Submission Time
Task F - Road of the King
User ha15
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 727 Byte
Status
Exec Time 102 ms
Memory 212608 KB

Judge Result

Set Name Score / Max Score Test Cases
sample 0 / 0 sample-01.txt, sample-02.txt, sample-03.txt
all 1000 / 1000 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 2 ms 384 KB
01-02.txt 1 ms 256 KB
01-03.txt 50 ms 211200 KB
01-04.txt 2 ms 896 KB
01-05.txt 50 ms 211200 KB
01-06.txt 55 ms 211584 KB
01-07.txt 99 ms 212480 KB
01-08.txt 102 ms 212608 KB
01-09.txt 102 ms 212608 KB
01-10.txt 102 ms 212608 KB
sample-01.txt 2 ms 2304 KB
sample-02.txt 64 ms 211840 KB
sample-03.txt 52 ms 108032 KB