Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(0), cin.tie(0);
- int N, C, mod; cin >> N >> C >> mod;
- auto modadd = [&](int &a, int b) {
- a += b;
- if (a >= mod) a -= mod;
- };
- vector dp(N+1, vector<int>(C+1, 0));
- dp[0][0] = 1;
- for (int c = C; c >= 1; --c) {
- for (int i = 0; i <= N-1; ++i) {
- for (int d = 0; d < c; ++d) modadd(dp[i+1][c-d], dp[i][d]);
- for (int d = c; d <= C; ++d) modadd(dp[i+1][d-c], dp[i][d]);
- }
- }
- cout << dp[N][0] << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement