제출 #1339229

#제출 시각아이디문제언어결과실행 시간메모리
1339229trungcanFestival (COCI25_festival)C++20
70 / 70
97 ms67216 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 5005;
const int MOD = 1e9 + 7;

int n, k, dp[N][N];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n >> k;

    //dp[i][j] la so cach xep hop sao cho con lai i keo, da xep j hop
    dp[n][0] = 1;
    for (int i = n; i > 0; --i)
        for (int j = 0; j <= k; ++j)
            if (dp[i][j]){
                //Tao 1 hop moi
                if (j < k)
                    dp[i - 1][j + 1] = (dp[i - 1][j + 1] + dp[i][j]) % MOD;
                //Xep 1 vien keo vao hop hien tai
                if (j)
                    dp[i - 1][j] = (dp[i - 1][j] + (dp[i][j] * 1LL * i) % MOD) % MOD;
            }

//    for (int i = n; i >= 0; --i)
//        for (int j = 0; j <= min(i, k); ++j) if (dp[i][j])
//            cout << i << " " << j << "\t" << dp[i][j] << "\n";

    cout << dp[0][k];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...