#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1000000007;
int add(int a, int b){ a += b; if(a >= MOD) a -= MOD; return a; }
int mul(int a, int b){ return (1LL*a*b)%MOD; }
int dp[2005][2005];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, a, b;
cin >> n >> 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] = add(dp[i][j], add(dp[i-1][j-1], dp[i-1][j]));
else{
dp[i][j] = add(dp[i][j], mul(j, dp[i-1][j+1]));
int mesta = j;
if(i > a) mesta--;
if(i > b) mesta--;
dp[i][j] = add(dp[i][j], mul(mesta, dp[i-1][j-1]));
}
}
}
cout << dp[n][1] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
1228 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
2 ms |
1188 KB |
Output is correct |
15 |
Correct |
1 ms |
1228 KB |
Output is correct |
16 |
Correct |
1 ms |
1208 KB |
Output is correct |
17 |
Correct |
2 ms |
1228 KB |
Output is correct |
18 |
Correct |
2 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
1228 KB |
Output is correct |
20 |
Correct |
1 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
1228 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
2 ms |
1188 KB |
Output is correct |
15 |
Correct |
1 ms |
1228 KB |
Output is correct |
16 |
Correct |
1 ms |
1208 KB |
Output is correct |
17 |
Correct |
2 ms |
1228 KB |
Output is correct |
18 |
Correct |
2 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
1228 KB |
Output is correct |
20 |
Correct |
1 ms |
1228 KB |
Output is correct |
21 |
Correct |
6 ms |
4588 KB |
Output is correct |
22 |
Correct |
7 ms |
4940 KB |
Output is correct |
23 |
Correct |
8 ms |
5452 KB |
Output is correct |
24 |
Correct |
38 ms |
16044 KB |
Output is correct |
25 |
Correct |
37 ms |
15940 KB |
Output is correct |
26 |
Correct |
40 ms |
15944 KB |
Output is correct |
27 |
Correct |
38 ms |
15804 KB |
Output is correct |
28 |
Correct |
23 ms |
12060 KB |
Output is correct |