Submission #5425765
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
template<int mod> struct ModInt {
using ll = long long;
int x;
template<class T>
ModInt(T a) {
x = a % mod;
if (x < 0) {
x += mod;
}
}
ModInt() : x(0) {}
inline ModInt& operator+=(const ModInt& rhs)
{
(*this) += rhs.x;
return *this;
}
template<class T>
inline ModInt& operator+=(const T rhs)
{
x += rhs % mod;
if (x < 0) x += mod;
x %= mod;
return *this;
}
inline ModInt& operator-=(const ModInt& rhs)
{
(*this) -= rhs.x;
return *this;
}
template<class T>
inline ModInt& operator-=(const T rhs)
{
x -= rhs % mod;
if (x < 0) x += mod;
x %= mod;
return *this;
}
inline ModInt& operator*=(const ModInt& rhs)
{
(*this) *= rhs.x;
return *this;
}
template<class T>
inline ModInt& operator*=(const T rhs)
{
ll res = (ll) x * (rhs % mod);
x = res % mod;
if (x < 0) x += mod;
return *this;
}
inline ModInt& operator/=(const ModInt& rhs)
{
(*this) /= rhs.x;
return *this;
}
template<class T>
inline ModInt& operator/=(const T rhs)
{
int t = rhs % mod;
if (t < 0) t += mod;
ll res = modpow(t);
(*this) *= res;
return *this;
}
inline ModInt& operator=(const ModInt& rhs)
{
(*this) = rhs.x;
return *this;
}
template<class T>
inline ModInt& operator=(const T rhs)
{
x = rhs % mod;
if (x < 0) x += mod;
return *this;
}
inline int operator==(const ModInt& rhs) const
{
return (*this) == rhs.x;
}
template<class T>
inline int operator==(const T rhs) const
{
ModInt t(rhs);
return (*this).x == t.x;
}
inline int operator!=(const ModInt& rhs) const
{
return (*this) != rhs.x;
}
inline int operator!=(const int rhs) const
{
ModInt t(rhs);
return (*this).x != t.x;
}
inline ModInt operator++(signed unused)
{
ModInt res((*this).x);
++(*this);
return res;
}
inline ModInt& operator++()
{
(*this) += 1;
return (*this);
}
inline ModInt operator--(signed unused)
{
ModInt res((*this).x);
--(*this);
return res;
}
inline ModInt& operator--()
{
(*this) -= 1;
return (*this);
}
inline ModInt operator+() const
{
return (*this);
}
inline ModInt operator-() const
{
return (*this).x ? ModInt(mod - (*this).x) : ModInt(0);
}
template<class T>
int modpow(const T val, int p = mod - 2)
{
if (p == 0) return 1;
if (p % 2) return (long long) val * modpow(val, p-1) % mod;
long long t = modpow(val, p/2);
int res = t * t % mod;
return res;
}
operator int() const
{
return x;
}
friend ostream& operator<<(ostream& lhs, const ModInt& rhs)
{
lhs << rhs.x;
return lhs;
}
friend istream& operator>>(istream& lhs, ModInt& rhs)
{
long long t;
lhs >> t;
rhs.x = t % mod;
if (rhs.x < 0) rhs += mod;
return lhs;
}
friend const ModInt operator+(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) += rhs;}
template<class T>
friend const ModInt operator+(const ModInt& lhs, const T rhs) {return ModInt(lhs) += rhs;}
template<class T>
friend const ModInt operator+(T lhs, const ModInt& rhs) {return ModInt(lhs) += rhs;}
friend const ModInt operator-(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) -= rhs;}
template<class T>
friend const ModInt operator-(const ModInt& lhs, const T rhs) {return ModInt(lhs) -= rhs;}
template<class T>
friend const ModInt operator-(T lhs, const ModInt& rhs) {return ModInt(lhs) -= rhs;}
friend const ModInt operator*(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) *= rhs;}
template<class T>
friend const ModInt operator*(const ModInt& lhs, const T rhs) {return ModInt(lhs) *= rhs;}
template<class T>
friend const ModInt operator*(T lhs, const ModInt& rhs) {return ModInt(lhs) *= rhs;}
friend const ModInt operator/(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) /= rhs;}
template<class T>
friend const ModInt operator/(const ModInt& lhs, const T rhs) {return ModInt(lhs) /= rhs;}
template<class T>
friend const ModInt operator/(T lhs, const ModInt& rhs) {return ModInt(lhs) /= rhs;}
template<class T>
friend const int operator==(T lhs, const ModInt& rhs) {return ModInt(lhs) == rhs;}
template<class T>
friend const int operator!=(T lhs, const ModInt& rhs) {return ModInt(lhs) != rhs;}
};
using modint = ModInt<1000000007>;
// i日目
// j孤立点
// k成分
modint dp[301][301][301];
#define reps(i, n, m) for (int i = n; i < m; i++)
#define rep(i, n) reps(i, 0, n)
int main()
{
int n, m;
cin >> n >> m;
dp[0][n-1][1] = 1;
rep(i, m) {
rep(j, n+1) {
rep(k, n+1) {
int e = n - k - j;
if (e < 0) continue;
if (j) if (k) {
dp[i+1][j-1][k] += j * dp[i][j][k];
} else {
dp[i+1][j-1][1] += j * dp[i][j][k];
}
dp[i+1][j][k] += e * dp[i][j][k];
dp[i+1][j][k+e] += k * dp[i][j][k];
}
}
}
cout << dp[m][0][n] << endl;
}
Submission Info
Submission Time |
|
Task |
F - Road of the King |
User |
spihill |
Language |
C++14 (GCC 5.4.1) |
Score |
1000 |
Code Size |
5154 Byte |
Status |
AC |
Exec Time |
366 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 |
34 ms |
106752 KB |
01-02.txt |
AC |
34 ms |
106752 KB |
01-03.txt |
AC |
34 ms |
106752 KB |
01-04.txt |
AC |
35 ms |
106752 KB |
01-05.txt |
AC |
34 ms |
106752 KB |
01-06.txt |
AC |
66 ms |
106752 KB |
01-07.txt |
AC |
343 ms |
106752 KB |
01-08.txt |
AC |
361 ms |
106752 KB |
01-09.txt |
AC |
364 ms |
106752 KB |
01-10.txt |
AC |
366 ms |
106752 KB |
sample-01.txt |
AC |
34 ms |
106752 KB |
sample-02.txt |
AC |
120 ms |
106752 KB |
sample-03.txt |
AC |
200 ms |
106752 KB |