이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |