This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e3+5;
const long long MOD = 1e9+7;
long long dp[MAXN][MAXN];
int n,a,b;
int main(){
cin>>n>>a>>b;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i==1 && j==1){
dp[i][j] = 1;
continue;
}
if(i==a||i==b){
dp[i][j] = dp[i-1][j-1]+dp[i-1][j];
dp[i][j]%=MOD;
}else{
dp[i][j] = dp[i-1][j+1]*j;
dp[i][j]%=MOD;
dp[i][j]+=dp[i-1][j-1]*(j-(i>a)-(i>b));
dp[i][j]%=MOD;
}
}
}
cout<<dp[n][1]<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |