[text] dice combinations

Viewer

copydownloadembedprintName: dice combinations
  1. // Problem: Dice Combinations
  2. // Contest: CSES - CSES Problem Set
  3. // URL: https://cses.fi/problemset/task/1633
  4. // Memory Limit: 512 MB
  5. // Time Limit: 1000 ms
  6. //
  7. // Author: anshupriya
  8. // Created: 2024-05-06 16:03:21
  9.  
  10. #include <bits/stdc++.h>
  11. using namespace std;
  12.  
  13. #define pfi(a) printf("%d", a);
  14. #define pfl(a) printf("%lld", a);
  15. #define pfin(a) printf("%d\n", a);
  16. #define pfln(a) printf("%lld\n", a);
  17. #define pfis(a) printf("%d ", a);
  18. #define pfls(a) printf("%lld ", a);
  19. #define sfi(a) scanf("%d", &a);
  20. #define sfl(a) scanf("%lld", &a);
  21. #define fast                        \
  22.   ios_base::sync_with_stdio(false); \
  23.   cin.tie(NULL);                    \
  24.   cout.tie(NULL)
  25. #define f(i, a, b) for (int i = a; i < b; i++)
  26. #define pb(a) push_back(a);
  27. #define mp(a, b) make_pair(a, b)
  28. #define ll long long
  29. #define F first
  30. #define S second
  31.  
  32. ll solve(int x, vector<int>& dp) {
  33.   if (dp[x] != -1) {
  34.     return dp[x];
  35.   }
  36.  
  37.   int ans = 0;
  38.   for (int i = 1; i <= 6; i++) {
  39.     if (x - i == 0) {
  40.       ans++;
  41.       ans = ans % 1000000007;
  42.     } else if (x - i > 0) {
  43.       ans = ans + solve(x - i, dp);
  44.       ans = ans % 1000000007;
  45.     } else if (x - i < 0) {
  46.       break;
  47.     }
  48.   }
  49.  
  50.   dp[x] = ans;
  51.   return ans;
  52. }
  53.  
  54. int main() {
  55.   int n;
  56.   cin >> n;
  57.   vector<int> dp(n + 1, -1);
  58.   ll answer = solve(n, dp);
  59.   cout << answer;
  60.  
  61.   return 0;
  62. }

Editor

You can edit this paste and save as new:


File Description
  • dice combinations
  • Paste Code
  • 06 May-2024
  • 1.35 Kb
You can Share it: