Submission #994237


Source Code Expand

#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
using namespace std;
const LL prime=1000000007;
int n;
LL memo[310][310][310];
LL solve(int left,int already,int goals){
  if(left==0)
    if(goals==n) return 1;
    else return 0;
  else if(memo[left][already][goals]!=-1) return memo[left][already][goals];
  else{
    LL answer=0;
    if(n-already-goals) answer+=solve(left-1,already+1,goals)*(n-already-goals);
    answer+=solve(left-1,already,goals)*already;
    answer+=solve(left-1,0,already+goals)*goals;
    return memo[left][already][goals]=answer%prime;
  }
}
int main(void)
{
  int m;
  cin >> n >> m;
  REP(i,301) REP(j,301) REP(k,301) memo[i][j][k]=-1;
  cout << solve(m,0,1) << endl;
  return 0;
}

Submission Info

Submission Time
Task F - Road of the King
User siotouto
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 860 Byte
Status AC
Exec Time 362 ms
Memory 220928 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 217 ms 220800 KB
01-02.txt AC 216 ms 220800 KB
01-03.txt AC 214 ms 220928 KB
01-04.txt AC 216 ms 220800 KB
01-05.txt AC 216 ms 220928 KB
01-06.txt AC 243 ms 220928 KB
01-07.txt AC 360 ms 220928 KB
01-08.txt AC 360 ms 220928 KB
01-09.txt AC 362 ms 220928 KB
01-10.txt AC 360 ms 220928 KB
sample-01.txt AC 215 ms 220800 KB
sample-02.txt AC 286 ms 220928 KB
sample-03.txt AC 232 ms 220800 KB