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>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define bit(s, i) (s & (1<<i))
using namespace std;
const int maxn = 2005;
const int mod = 1e9+7;
typedef long long ll;
typedef pair < int, int > ii;
int n, st, en;
ll dp[maxn][maxn];
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen(".inp","r",stdin);
//freopen(".out","w",stdout);
cin >> n >> st >> en;
memset(dp, 0, sizeof dp);
dp[0][0] = 1;
for(int i=1;i<=n;++i)
for(int j=1;j<=i;++j)
{
if(i == st || i == en)
{
dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % mod;
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
// cout << i << ' ' << j << ' ' << dp[i][j] << endl;
continue;
}
ll cur = dp[i - 1][j + 1] * j;
dp[i][j] = (dp[i][j] + cur) % mod;
int x = j;
if(st < i) -- x;
if(en < i) -- x;
cur = dp[i - 1][j - 1] * x;
dp[i][j] = (dp[i][j] + cur) % mod;
// cout << i << ' ' << j << ' ' << dp[i][j] << endl;
}
cout << dp[n][1];
}
# | 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... |