이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 2000;
const int MOD = 1e9 + 7;
int dp[NMAX + 1][NMAX + 2];
int main() {
int n, start, finish;
cin >> n >> start >> finish;
dp[0][1] = 1;
for ( int i = 0; i < n; i ++ ) {
for ( int j = 0; j <= n; j ++ ) {
if ( i + 1 == start || i + 1 == finish ) {
dp[i + 1][j] = ( dp[i + 1][j] + dp[i][j] ) % MOD;
if ( j >= 1 ) dp[i + 1][j - 1] = ( dp[i + 1][j - 1] + dp[i][j] ) % MOD;
} else {
dp[i + 1][j + 1] = ( dp[i + 1][j + 1] + (long long)dp[i][j] * j ) % MOD;
if ( j >= 1 ) dp[i + 1][j - 1] = ( dp[i + 1][j - 1] + (long long)dp[i][j] * ( j - ( i + 1 < start ) - ( i + 1 < finish ) ) ) % MOD;
}
}
}
cout << dp[n][0];
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... |