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 ld long double
#define int long long
#define endl "\n"
const int N = 2000,mod = 1e9 + 7;
int dp[N + 1][N + 1][2][2],n,a,b;
int f(int pos,int comp,bool front,bool back) {
if(comp < 0) return 0;
if(pos == n + 1) {
return comp == 1;
}
if(dp[pos][comp][front][back] != -1) return dp[pos][comp][front][back];
if(pos == a) {
int res = 0;
res = (res + f(pos + 1,comp + 1,0,back))%mod;
if(!front) {
res = (res + f(pos + 1,comp,1,back))%mod;
}
return dp[pos][comp][front][back] = res;
}
if(pos == b) {
int res = 0;
res = (res + f(pos + 1,comp + 1,front,0))%mod;
if(!back) {
res = (res + f(pos + 1,comp,front,1))%mod;
}
return dp[pos][comp][front][back] = res;
}
int res = 0;
if(!front && pos < a) {
res = (res + f(pos + 1,comp,1,back))%mod;
}
if(pos < a) {
res = (res + f(pos + 1,comp + 1,0,back))%mod;
}
if(!back && pos < b) {
res = (res + f(pos + 1,comp,front,1))%mod;
}
if(pos < b) {
res = (res + f(pos + 1,comp + 1,front,0))%mod;
}
res = (res + (f(pos + 1,comp + 1,front,back) * (comp - 1))%mod)%mod;
res = (res + (f(pos + 1,comp - 1,front,back) * (comp - 1))%mod)%mod;
return dp[pos][comp][front][back] = res;
}
signed main() {
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
freopen("kangaroo.in","r",stdin);
freopen("kangaroo.out","w",stdout);
cin>>n>>a>>b;
memset(dp,-1,sizeof(dp));
cout<<f(2,1,0,0)<<endl;
return 0;
}
Compilation message (stderr)
kangaroo.cpp: In function 'int main()':
kangaroo.cpp:59:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | freopen("kangaroo.in","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
kangaroo.cpp:60:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | freopen("kangaroo.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |