# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
333748 | phathnv | Kangaroo (CEOI16_kangaroo) | C++11 | 18 ms | 14188 KiB |
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>
#define mp make_pair
#define X first
#define Y second
#define taskname "kangaroo"
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
const int N = 2001;
const int MOD = 1e9 + 7;
int sum(int a, int b){
a += b;
a -= (a >= MOD) * MOD;
return a;
}
int mul(int a, int b){
return (ll) a * b % MOD;
}
int n, dp[N][N], cs, cf;
void readInput(){
cin >> n >> cs >> cf;
}
void solve(){
dp[0][0] = 1;
int fixed = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= i; j++)
if (i == cs || i == cf)
dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD;
else
dp[i][j] = sum(mul(dp[i - 1][j + 1], j), mul(dp[i - 1][j - 1], j - fixed));
fixed += (i == cs || i == cf);
}
cout << dp[n][1];
}
int main(){
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
readInput();
solve();
return 0;
}
Compilation message (stderr)
# | 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... |