#include <bits/stdc++.h>
using namespace std;
const int mx=2000;
const int mod=1000000007;
typedef long long ll;
int n,m;
int st,en;
//(i,x,state);
map<int,int>mp;
ll dp[mx][mx][3];
ll solve(int i,int x,int dir){
if(i==en){
if(x==n){
return 1;}
return 0;
}
ll &ret=dp[i][x][dir];
if(ret!=-1){return ret;}
ret=0;
if(dir==0){
for(int j=i+1;j<=n;j++){
if(mp[j]){continue;}
mp[j]=1;
ret=(ret+solve(j,x+1,dir^1))%mod;
mp[j]=0;
}
}else{
for(int j=i-1;j>=1;j--){
if(mp[j]){continue;}
mp[j]=1;
ret=(ret+solve(j,x+1,dir^1))%mod;
mp[j]=0;
}
}return ret%mod;
}
int main() {
cin>>n>>st>>en;
for(int i=0;i<=mx;i++){
for(int j=0;j<=mx;j++){
dp[i][j][0]=dp[i][j][1]=-1;
}
}
mp[st]=1;
cout<<(solve(st,1,0)+solve(st,1,1))%mod;
}
Compilation message
kangaroo.cpp: In function 'int main()':
kangaroo.cpp:44:34: warning: iteration 2000 invokes undefined behavior [-Waggressive-loop-optimizations]
44 | dp[i][j][0]=dp[i][j][1]=-1;
| ~~~~~~~~~~~^~~
kangaroo.cpp:43:20: note: within this loop
43 | for(int j=0;j<=mx;j++){
| ~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
173 ms |
190716 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
173 ms |
190716 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
173 ms |
190716 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
173 ms |
190716 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |