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;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;
const int MOD = 1e9 + 7, MAX_N = 2e3 + 10;
int N, S, E, Dy[MAX_N][MAX_N];
void add(int &a, int b) {
if((a+=b) >= MOD) a -= MOD;
if(a < 0) a += MOD;
}
int main() {
cin >> N >> S >> E;
Dy[0][0] = 1;
int cnt = 0;
for(int i=1; i<=N; i++) {
if(i == S || i == E) {
for(int j=0; j<=N; j++) {
add(Dy[i][j], Dy[i-1][j]);
add(Dy[i][j], Dy[i-1][j-1]);
}
cnt++;
} else {
for(int j=0; j<=N; j++) {
if(j) add(Dy[i][j], 1ll * Dy[i-1][j-1] * (j - cnt) % MOD);
add(Dy[i][j], 1ll * Dy[i-1][j+1] * j % MOD);
}
}
}
printf("%d\n", Dy[N][1]);
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... |