# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
789786 | chengcheng567 | Kangaroo (CEOI16_kangaroo) | C++14 | 20 ms | 33160 KiB |
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;
#define int long long
const int MOD=1e9+7;
int dp[2100][2100],n,a,b;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);cin>>n>>a>>b;
if(a>b)swap(a,b);dp[1][1]=1;
for(int i=2;i<=n;i++)
for(int j=1;j<=n;j++)
if(i==a||i==b)dp[i][j]=(dp[i-1][j-1]+dp[i-1][j])%MOD;
else if(i<a)dp[i][j]=(j*dp[i-1][j-1]+j*dp[i-1][j+1])%MOD;
else if(a<i&&i<b)dp[i][j]=((j-1)*dp[i-1][j-1]+j*dp[i-1][j+1])%MOD;
else dp[i][j]=(max(0ll,j-2)*dp[i-1][j-1]+j*dp[i-1][j+1])%MOD;
return cout<<dp[n][1],0;
}
Compilation message (stderr)
# | 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... |