Submission #2559071


Source Code Expand

#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-(x)))
#define MP make_pair
#define fi first
#define se second
#ifdef __LOCAL_DEBUG__
# define _debug(fmt, ...) fprintf(stderr, "\033[94m%s: " fmt "\n\033[0m", \
    __func__, ##__VA_ARGS__)
#else
# define _debug(...) ((void) 0)
#endif
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int maxn = 300 + 11;
const int MOD = 1e9 + 7;
int N, M, T;
LL dp[maxn][maxn][maxn];
int main(){
    cin >> N >> M;
    dp[0][1][1] = 1;
    for (int i = 0; i < M; i++){
        for (int j = 0; j <= min(i + 1, N); j++){
            for (int k = 0; k <= j; k++){
                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;
                dp[i+1][j+1][k] %= MOD;
                dp[i+1][j][k] %= MOD;
                dp[i+1][j][j] %= MOD;
            }
        }
    }
    cout << dp[M][N][N] % MOD << endl;
    return 0;
}

Submission Info

Submission Time
Task F - Road of the King
User vjudge1
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 1115 Byte
Status AC
Exec Time 79 ms
Memory 227584 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 3
AC × 16
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 1 ms 256 KB
01-02.txt AC 1 ms 256 KB
01-03.txt AC 45 ms 225536 KB
01-04.txt AC 1 ms 256 KB
01-05.txt AC 45 ms 225536 KB
01-06.txt AC 52 ms 225536 KB
01-07.txt AC 79 ms 225536 KB
01-08.txt AC 79 ms 227584 KB
01-09.txt AC 79 ms 227584 KB
01-10.txt AC 79 ms 227584 KB
sample-01.txt AC 2 ms 2304 KB
sample-02.txt AC 62 ms 225536 KB
sample-03.txt AC 27 ms 112896 KB