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 <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <iomanip>
#include <map>
#include <queue>
using namespace std;
const int maxn = 2e3;
int n,s,e;
long long dp[maxn+5][maxn+5];
const int MOD = 1e9+7;
void solve()
{
cin >> n >> s >> e;
dp[1][1] = 1;
for(int i = 1; i < n; i++)
{
for(int j = 1; j <= i; j++)
{
if(i + 1 == s || i + 1 == e) dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % MOD, dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD;
else
{
dp[i+1][j+1] = (dp[i+1][j+1] + (j - (i >= s) - (i >= e)) * dp[i][j]) % MOD;
dp[i+1][j-1] = (dp[i+1][j-1] + (j - 1) * dp[i][j]) % MOD;
}
}
}
cout << dp[n][1];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
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... |