#include <bits/stdc++.h>
#define int int64_t
using namespace std;
const int maxn = 2010;
const int mod = 1e9 + 7;
int dp[maxn][maxn];
int n;
int ini, fim;
int solve(int i, int k) {
if (i > n && k == 1) return 1;
else if (i > n) return 0;
if (dp[i][k] != -1) return dp[i][k];
int caso1 = solve(i+1, k+1);
int caso2 = (k > 1 || i == ini || i == fim ? (i == ini || i == fim ? solve(i+1, k) : solve(i+1, k-1)) : 0);
if (i == ini || i == fim) return dp[i][k] = (caso1 + caso2)%mod;
else if (i < ini && i < fim) return dp[i][k] = ( caso1*(k+1) + caso2*(k-1) )%mod;
else if (i < ini || i < fim) return dp[i][k] = ( caso1*k + caso2*(k-1) )%mod;
return dp[i][k] = ((k-1)*( caso1 + caso2 ))%mod;
}
int32_t main() {
memset(dp, -1, sizeof dp);
cin >> n;
cin >> ini >> fim;
cout << solve(1, 0) << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31980 KB |
Output is correct |
2 |
Correct |
17 ms |
31980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31980 KB |
Output is correct |
2 |
Correct |
17 ms |
31980 KB |
Output is correct |
3 |
Correct |
18 ms |
31980 KB |
Output is correct |
4 |
Correct |
17 ms |
31980 KB |
Output is correct |
5 |
Correct |
16 ms |
31980 KB |
Output is correct |
6 |
Correct |
17 ms |
31980 KB |
Output is correct |
7 |
Correct |
17 ms |
31980 KB |
Output is correct |
8 |
Correct |
17 ms |
31980 KB |
Output is correct |
9 |
Correct |
17 ms |
31980 KB |
Output is correct |
10 |
Correct |
19 ms |
31980 KB |
Output is correct |
11 |
Correct |
17 ms |
31980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31980 KB |
Output is correct |
2 |
Correct |
17 ms |
31980 KB |
Output is correct |
3 |
Correct |
18 ms |
31980 KB |
Output is correct |
4 |
Correct |
17 ms |
31980 KB |
Output is correct |
5 |
Correct |
16 ms |
31980 KB |
Output is correct |
6 |
Correct |
17 ms |
31980 KB |
Output is correct |
7 |
Correct |
17 ms |
31980 KB |
Output is correct |
8 |
Correct |
17 ms |
31980 KB |
Output is correct |
9 |
Correct |
17 ms |
31980 KB |
Output is correct |
10 |
Correct |
19 ms |
31980 KB |
Output is correct |
11 |
Correct |
17 ms |
31980 KB |
Output is correct |
12 |
Correct |
19 ms |
31980 KB |
Output is correct |
13 |
Correct |
18 ms |
31980 KB |
Output is correct |
14 |
Correct |
17 ms |
31980 KB |
Output is correct |
15 |
Correct |
18 ms |
31980 KB |
Output is correct |
16 |
Correct |
20 ms |
31980 KB |
Output is correct |
17 |
Correct |
17 ms |
31980 KB |
Output is correct |
18 |
Correct |
17 ms |
32000 KB |
Output is correct |
19 |
Correct |
21 ms |
31980 KB |
Output is correct |
20 |
Correct |
17 ms |
32000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
31980 KB |
Output is correct |
2 |
Correct |
17 ms |
31980 KB |
Output is correct |
3 |
Correct |
18 ms |
31980 KB |
Output is correct |
4 |
Correct |
17 ms |
31980 KB |
Output is correct |
5 |
Correct |
16 ms |
31980 KB |
Output is correct |
6 |
Correct |
17 ms |
31980 KB |
Output is correct |
7 |
Correct |
17 ms |
31980 KB |
Output is correct |
8 |
Correct |
17 ms |
31980 KB |
Output is correct |
9 |
Correct |
17 ms |
31980 KB |
Output is correct |
10 |
Correct |
19 ms |
31980 KB |
Output is correct |
11 |
Correct |
17 ms |
31980 KB |
Output is correct |
12 |
Correct |
19 ms |
31980 KB |
Output is correct |
13 |
Correct |
18 ms |
31980 KB |
Output is correct |
14 |
Correct |
17 ms |
31980 KB |
Output is correct |
15 |
Correct |
18 ms |
31980 KB |
Output is correct |
16 |
Correct |
20 ms |
31980 KB |
Output is correct |
17 |
Correct |
17 ms |
31980 KB |
Output is correct |
18 |
Correct |
17 ms |
32000 KB |
Output is correct |
19 |
Correct |
21 ms |
31980 KB |
Output is correct |
20 |
Correct |
17 ms |
32000 KB |
Output is correct |
21 |
Correct |
23 ms |
31980 KB |
Output is correct |
22 |
Correct |
23 ms |
31980 KB |
Output is correct |
23 |
Correct |
22 ms |
31980 KB |
Output is correct |
24 |
Correct |
57 ms |
32256 KB |
Output is correct |
25 |
Correct |
60 ms |
32236 KB |
Output is correct |
26 |
Correct |
58 ms |
32108 KB |
Output is correct |
27 |
Correct |
57 ms |
32108 KB |
Output is correct |
28 |
Correct |
37 ms |
31980 KB |
Output is correct |