Advertisement
volochai

Vologda 9-11 2023. B

Dec 13th, 2023
697
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4. #define all(x) (x).begin(), (x).end()
  5. #define rall(x) (x).rbegin(), (x).rend()
  6. #define watch(x) cout << (#x) << " : " << x << '\n'
  7. #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  8.  
  9. using namespace std;
  10.  
  11. const int N = 33;
  12. ll dp[N][N][N][N];
  13.  
  14. void solve() {
  15.     int n, k;
  16.     cin >> n >> k;
  17.  
  18.     dp[0][0][0][0] = 1;
  19.     for (int i = 1; i <= n; i++) {
  20.         for (int a = 0; a <= k; a++)
  21.             for (int b = 0; b <= k; b++)
  22.                 for (int c = 0; c <= k; c++) {
  23.                     if (a + 1 <= k) dp[i][a + 1][b][c] += dp[i-1][a][b][c];
  24.                     if (b + 1 <= k) dp[i][a][b + 1][c] += dp[i-1][a][b][c];
  25.                     if (c + 1 <= k) dp[i][a][b][c + 1] += dp[i-1][a][b][c];
  26.                 }
  27.     }
  28.  
  29.     ll ans = 0ll;
  30.     for (int a = 0; a <= k; a++)
  31.         for (int b = 0; b <= k; b++)
  32.             for (int c = 0; c <= k; c++)
  33.                 ans += dp[n][a][b][c];
  34.  
  35.     cout << ans << '\n';
  36. }
  37.  
  38. main() {
  39.     boost;
  40.     solve();
  41.     return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement