This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
/*
tutorial :
https://codeforces.com/blog/entry/47764
(ctrl f it)
N celule 1->n
cangur celula cs
sare in alta celula
se opreste in celula cf
n-1 sarituri arbritare
schimba directia in care sare
*/
int n, cf, cs;
const int MOD=1e9+7, N=2e3+1;
int add(int x, int y){
return (x+y)%MOD;
}
int mul(int x, int y){
return (1LL*x*y)%MOD;
}
int dp[N][N];
int main(){
ifstream fin("kangaroo.in");
ofstream fout("kangaroo.out");
fin>>n>>cs>>cf;
fin.close();
dp[0][0]=1;
for(int i=1; i<=n; ++i){
for(int c=1;c<=i;++c){
if(!(i==cs or i==cf)){
dp[i][c]=add(
mul(dp[i-1][c-1], c-(i>cs)-(i>cf)),
mul(dp[i-1][c+1], c)
);
}else{
dp[i][c]=add(dp[i-1][c-1],dp[i-1][c]);
}
}
}
int ans=dp[n][1];
fout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |