Advertisement
SorahISA

H. Hitoshizuku

Sep 25th, 2024
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     ios_base::sync_with_stdio(0), cin.tie(0);
  6.    
  7.     int N, C, mod; cin >> N >> C >> mod;
  8.    
  9.     auto modadd = [&](int &a, int b) {
  10.         a += b;
  11.         if (a >= mod) a -= mod;
  12.     };
  13.    
  14.     vector dp(N+1, vector<int>(C+1, 0));
  15.     dp[0][0] = 1;
  16.    
  17.     for (int c = C; c >= 1; --c) {
  18.         for (int i = 0; i <= N-1; ++i) {
  19.             for (int d = 0; d <  c; ++d) modadd(dp[i+1][c-d], dp[i][d]);
  20.             for (int d = c; d <= C; ++d) modadd(dp[i+1][d-c], dp[i][d]);
  21.         }
  22.     }
  23.     cout << dp[N][0] << "\n";
  24.    
  25.     return 0;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement