#include <bits/stdc++.h>
using namespace std;
const int N=2005,MOD=1e9+7;
long long mem[N][N];
int n,a,b;
int main()
{
cin >> n >> a >> b;
mem[1][1]=1;
for(int i=2;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==a||i==b)
{
mem[i][j]=mem[i-1][j]+mem[i-1][j-1];
if(mem[i][j]>=MOD) mem[i][j]-=MOD;
continue;
}
mem[i][j]=mem[i-1][j-1]*(j-(i>a)+(i>b)); // add a new component
mem[i][j]%=MOD;
mem[i][j]+=mem[i-1][j+1]*j; // combine two existing components;
mem[i][j]%=MOD;
}
}
cout << mem[n][1] << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |