Submission #992886


Source Code Expand

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
int bsr(int x) { return 31 - __builtin_clz(x); }


template<class T>
T pow(T x, ll n, T r = 1) {
    while (n) {
        if (n & 1) r *= x;
        x *= x;
        n >>= 1;
    }
    return r;
}

template<uint MD>
struct ModInt {
    uint v;
    ModInt() : v{0} {}
    ModInt(ll v) : v{normS(v%MD+MD)} {}
    static uint normS(const uint &x) {return (x<MD)?x:x-MD;};
    static ModInt make(const uint &x) {ModInt m; m.v = x; return m;}
    ModInt operator+(const ModInt &r) const {return make(normS(v+r.v));}
    ModInt operator-(const ModInt &r) const {return make(normS(v+MD-r.v));}
    ModInt operator*(const ModInt &r) const {return make((ull)v*r.v%MD);}
    ModInt& operator+=(const ModInt &r) {return *this=*this+r;}
    ModInt& operator-=(const ModInt &r) {return *this=*this-r;}
    ModInt& operator*=(const ModInt &r) {return *this=*this*r;}
    static ModInt inv(const ModInt &x) {
        return pow(ModInt(x), MD-2);
    }
};
using Mint = ModInt<TEN(9)+7>;

const int MN = 330;
int n;


Mint dp[MN][MN][MN];
bool used[MN][MN][MN] = {};
Mint calc(int m, int a, int b) {
    if (m == 0) {
        if (a == n) return 1;
        return 0;
    }
    if (used[m][a][b]) return dp[m][a][b];
    used[m][a][b] = true;
    Mint &ans = dp[m][a][b]; ans = 0;
    ans += calc(m-1, a+b, 0) * a;
    ans += calc(m-1, a, b) * b;
    ans += calc(m-1, a, b+1) * (n-a-b);
    return ans;
}

int main() {
    cout << setprecision(20);
    int m;
    cin >> n >> m;
    cout << calc(m, 1, 0).v << endl;
    return 0;
}

Submission Info

Submission Time
Task F - Road of the King
User yosupo
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 1973 Byte
Status AC
Exec Time 389 ms
Memory 156160 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 3
AC × 13
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
Case Name Status Exec Time Memory
01-01.txt AC 146 ms 140672 KB
01-02.txt AC 146 ms 140672 KB
01-03.txt AC 385 ms 156160 KB
01-04.txt AC 145 ms 140672 KB
01-05.txt AC 385 ms 156160 KB
01-06.txt AC 386 ms 156160 KB
01-07.txt AC 383 ms 156032 KB
01-08.txt AC 388 ms 156160 KB
01-09.txt AC 386 ms 156160 KB
01-10.txt AC 389 ms 156160 KB
sample-01.txt AC 146 ms 140672 KB
sample-02.txt AC 388 ms 156160 KB
sample-03.txt AC 176 ms 144768 KB