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;
const int N=2005;
const int MOD=1000000007;
int dp[N][N];
inline void trans(long long val,int id,int col){
if(col<0)
return;
val%=MOD;
dp[id][col]+=val;
if(dp[id][col]>MOD)
dp[id][col]-=MOD;
}
int main()
{
int n,cs,cf;
scanf("%d%d%d",&n,&cs,&cf);
if(cf<cs)
swap(cf,cs);
dp[1][0]=1;
for(int i=1;i<cs;i++){
for(int j=0;j<i;j++){
trans(dp[i][j],i+1,j+1);
trans(1LL*dp[i][j]*(j-1)*j,i+1,j-1);
}
}
for(int j=0;j<cs;j++){
trans(dp[cs][j],cs+1,j);
trans(1LL*dp[cs][j]*j,cs+1,j-1);
}
for(int i=cs+1;i<cf;i++){
for(int j=0;j<i;j++){
trans(dp[i][j],i+1,j+1);
trans(1LL*dp[i][j]*(j)*j,i+1,j-1);
}
}
for(int j=0;j<cf;j++){
trans(dp[cf][j],cf+1,j);
trans(1LL*dp[cf][j]*j,cf+1,j-1);
}
for(int i=cf+1;i<=n;i++){
for(int j=0;j<i;j++){
trans(dp[i][j],i+1,j+1);
trans(1LL*dp[i][j]*(j+1)*j,i+1,j-1);
}
}
printf("%d",dp[n][0]);
return 0;
}
Compilation message (stderr)
kangaroo.cpp: In function 'int main()':
kangaroo.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
17 | scanf("%d%d%d",&n,&cs,&cf);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# | 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... |