Submission #5024961
Source Code Expand
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fin(x) freopen(x,"r",stdin)
#define fout(x) freopen(x,"w",stdout)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll inf=0xc0c0c0c0c0c0c0c0;
const double pi=acos(-1);
const int MAX=305;
const ll mod=1e9+7;
ll dp[2][MAX][MAX];//len,maxid,connectone
ll N,M;
void add(ll &a,ll b){a=(a+b)%mod;}
ll fact(ll x)
{
ll res=1;
while(x)
{
res=res*x%mod;
x--;
}
return res;
}
int main()
{
scanf("%lld%lld",&N,&M);
dp[0][1][1]=1;
for(int i=0;i<M;i++)
{
int last=i&1;
int now=last^1;
mem(dp[now],0);
for(int j=0;j<=N;j++)
for(int k=0;k<=j;k++)
if(dp[last][j][k])
{
add(dp[now][j][j],dp[last][j][k]*k%mod);//connect 1
if(j<N)
add(dp[now][j+1][k],dp[last][j][k]);//new
add(dp[now][j][k],dp[last][j][k]*(j-k)%mod);//connect not 1
}
}
printf("%lld\n",dp[M&1][N][N]*fact(N-1)%mod);
return 0;
}
Submission Info
Submission Time
2019-04-19 17:46:08+0900
Task
F - Road of the King
User
vjudge3
Language
C++14 (GCC 5.4.1)
Score
1000
Code Size
1043 Byte
Status
AC
Exec Time
58 ms
Memory
1664 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:32:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld",&N,&M);
^
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
2 ms
1024 KB
01-02.txt
AC
2 ms
1664 KB
01-03.txt
AC
12 ms
1664 KB
01-04.txt
AC
2 ms
1024 KB
01-05.txt
AC
13 ms
1664 KB
01-06.txt
AC
21 ms
1664 KB
01-07.txt
AC
57 ms
1664 KB
01-08.txt
AC
58 ms
1664 KB
01-09.txt
AC
58 ms
1664 KB
01-10.txt
AC
58 ms
1664 KB
sample-01.txt
AC
2 ms
1664 KB
sample-02.txt
AC
33 ms
1664 KB
sample-03.txt
AC
17 ms
1664 KB