Submission #316360

# Submission time Handle Problem Language Result Execution time Memory
316360 2020-10-26T06:50:11 Z BeanZ Kangaroo (CEOI16_kangaroo) C++14
0 / 100
1 ms 384 KB
// 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][0];
}
/*
*/

Compilation message

kangaroo.cpp: In function 'int main()':
kangaroo.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   13 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kangaroo.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   14 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct