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 <vector>
#include <queue>
#include <cstring>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <algorithm>
#include <stack>
using namespace std;
#define speedup ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
const ll MOD = 1e9+7, MAXN = 5*1e6+5;
int main() {
speedup
int n, a, b; cin >> n >> a >> b;
vector<vector<ll>> dp(n+1, vector<ll>(n+1));
dp[1][1] = 1;
for (int i = 2; i <= n; i++){
for (int j = 1; j <= i; j++){
if (i == a || i == b){
dp[i][j] = (dp[i-1][j]+dp[i-1][j-1])%MOD;
}else{
dp[i][j] = (dp[i-1][j+1]*j+dp[i-1][j-1]*(max(j-(i>a)-(i>b), 0)))%MOD;
}
}
}
if (dp[n][1] < 0){
dp[n][1] += MOD;
}
cout << dp[n][1] << endl;
return 0;
}
# | 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... |