#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int n, cs, cf;
ll dp[2005][2005];
ll solve(int i, int k) {
if (k < 0) return 0ll;
if (i > n) return k == 1;
if (dp[i][k] != -1) return dp[i][k];
ll& ans = dp[i][k];
ans = 0;
if (i == cs || i == cf) {
ll op1 = solve(i + 1, k);
ll op2 = solve(i + 1, k + 1);
return ans = (op1 + op2) % MOD;
}
if (i < cs) {
ll op1 = (1ll * (k - 1) * solve(i + 1, k - 1)) % MOD;
ll op2 = (1ll * (k + 1) * solve(i + 1, k + 1)) % MOD;
return ans = (op1 + op2) % MOD;
}
if (i < cf) {
ll op1 = (1ll * (k - 1) * solve(i + 1, k - 1)) % MOD;
ll op2 = (1ll * k * solve(i + 1, k + 1)) % MOD;
return ans = (op1 + op2) % MOD;
}
ll op1 = (1ll * (k - 1) * solve(i + 1, k - 1)) % MOD;
ll op2 = (1ll * (k - 1) * solve(i + 1, k + 1)) % MOD;
return ans = (op1 + op2) % MOD;
}
int main(){
scanf("%d %d %d", &n, &cs, &cf);
memset(dp, -1, sizeof dp);
printf("%lld\n", solve(1, 0));
return 0;
}
Compilation message
kangaroo.cpp: In function 'int main()':
kangaroo.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
39 | scanf("%d %d %d", &n, &cs, &cf);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
31724 KB |
Output is correct |
2 |
Correct |
19 ms |
31724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
31724 KB |
Output is correct |
2 |
Correct |
19 ms |
31724 KB |
Output is correct |
3 |
Correct |
21 ms |
31724 KB |
Output is correct |
4 |
Correct |
19 ms |
31724 KB |
Output is correct |
5 |
Correct |
19 ms |
31724 KB |
Output is correct |
6 |
Correct |
18 ms |
31724 KB |
Output is correct |
7 |
Incorrect |
18 ms |
31724 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
31724 KB |
Output is correct |
2 |
Correct |
19 ms |
31724 KB |
Output is correct |
3 |
Correct |
21 ms |
31724 KB |
Output is correct |
4 |
Correct |
19 ms |
31724 KB |
Output is correct |
5 |
Correct |
19 ms |
31724 KB |
Output is correct |
6 |
Correct |
18 ms |
31724 KB |
Output is correct |
7 |
Incorrect |
18 ms |
31724 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
31724 KB |
Output is correct |
2 |
Correct |
19 ms |
31724 KB |
Output is correct |
3 |
Correct |
21 ms |
31724 KB |
Output is correct |
4 |
Correct |
19 ms |
31724 KB |
Output is correct |
5 |
Correct |
19 ms |
31724 KB |
Output is correct |
6 |
Correct |
18 ms |
31724 KB |
Output is correct |
7 |
Incorrect |
18 ms |
31724 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |