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<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
// #pragma GCC optimize("Ofast")
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 0, n + 1)
#define SZ(x) (int)(x).size()
#define pb push_back
#define pf push_front
#define eb emplace_back
#define f first
#define s second
#define lowbit(x) x&-x
#define ckmin(a, b) a = min(a, b)
#define ckmax(a, b) a = max(a, b)
#define int long long
const int INF = 1e18;
const int N = 1e9 + 7;
const int maxn = 2005;
ll dp[maxn][maxn];
signed main(void){
fastio;
int n, s, t;
cin>>n>>s>>t;
dp[0][0] = 1;
int cnt = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= i; j++){
if(s == i || t == i){
cnt++;
dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % N;
}
else dp[i][j] = (dp[i - 1][j + 1] * j + dp[i - 1][j - 1] * (j - cnt)) % N;
}
}
cout<<dp[n][1]<<"\n";
}
# | 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... |