# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
316361 | BeanZ | Kangaroo (CEOI16_kangaroo) | C++14 | 65 ms | 31740 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.
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 105;
const int mod = 1e9 + 7;
ll dp[2005][2005];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("A.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n, cs, cf;
cin >> n >> cs >> cf;
// dp[i][j] la xet den thang thu i va dang co j nhom loai 1
dp[0][0] = 1;
for (int i = 1; i <= n; i++){
for (int j = 0; j <= n; j++){
if (cs == i){
// mo mot nhom moi
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
// ghep voi mot nhom loai 1
dp[i][j] = (dp[i][j] + dp[i - 1][j + 1] * (j + 1)) % mod;
} else if (cf == i){
// mo mot nhom moi
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
// ghep voi mot nhom loai 1
dp[i][j] = (dp[i][j] + dp[i - 1][j + 1] * (j + 1)) % mod;
} else {
// mo mot nhom moi
if (j > 0) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % mod;
// ghep 2 nhom loai 1 voi nhau
dp[i][j] = (dp[i][j] + dp[i - 1][j + 1] * (j + 1) * j) % mod;
// ghep 1 nhom loai 1 va mot nhom loai 2
if (i > cs) dp[i][j] = (dp[i][j] + dp[i - 1][j + 1] * (j + 1)) % mod;
// ghep 1 nhom loai 1 va mot nhom loai 3
if (i > cf) dp[i][j] = (dp[i][j] + dp[i - 1][j + 1] * (j + 1)) % mod;
}
//cout << dp[i][j] << " ";
}
//cout << endl;
}
cout << dp[n - 1][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... |