This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//https://oj.uz/problem/view/CEOI16_kangaroo
#include<bits/stdc++.h>
const int N = 2005;
const int mod = 1e9 + 7;
using namespace std;
int n, dp[N][N], s, e;
void add(int&a, int b){
a += b; if (a >= mod) a -= mod; if (a < 0) a += mod;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> s >> e;
if (s > e) swap(s, e);
dp[0][0] = 1;
for (int i = 1; i < n; i++){
for (int j = 1; j <= n; j++){
if (i != s && i != e){
if (i >= e){
add(dp[i][j], 1LL * dp[i-1][j+1] * (j-1) * (j-2) % mod);
}
else{
if (i >= s){
add(dp[i][j], 1LL * dp[i-1][j+1] * j * j % mod);
}
else{
add(dp[i][j], 1LL * dp[i-1][j+1] * (j+1) * j % mod);
}
}
}
else{
if (i == s){
add(dp[i][j], 1LL * dp[i-1][j] * j % mod);
}
else{
add(dp[i][j], 1LL * dp[i-1][j] * (j-1) % mod);
}
}
add(dp[i][j], dp[i-1][j-1]);
}
}
if (e == n) cout << dp[n-1][1];
else cout << dp[n-1][2];
}
# | 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... |