- // Problem: Dice Combinations
- // Contest: CSES - CSES Problem Set
- // URL: https://cses.fi/problemset/task/1633
- // Memory Limit: 512 MB
- // Time Limit: 1000 ms
- //
- // Author: anshupriya
- // Created: 2024-05-06 16:03:21
- #include <bits/stdc++.h>
- using namespace std;
- #define pfi(a) printf("%d", a);
- #define pfl(a) printf("%lld", a);
- #define pfin(a) printf("%d\n", a);
- #define pfln(a) printf("%lld\n", a);
- #define pfis(a) printf("%d ", a);
- #define pfls(a) printf("%lld ", a);
- #define sfi(a) scanf("%d", &a);
- #define sfl(a) scanf("%lld", &a);
- #define fast \
- ios_base::sync_with_stdio(false); \
- cin.tie(NULL); \
- cout.tie(NULL)
- #define f(i, a, b) for (int i = a; i < b; i++)
- #define pb(a) push_back(a);
- #define mp(a, b) make_pair(a, b)
- #define ll long long
- #define F first
- #define S second
- ll solve(int x, vector<int>& dp) {
- if (dp[x] != -1) {
- return dp[x];
- }
- int ans = 0;
- for (int i = 1; i <= 6; i++) {
- if (x - i == 0) {
- ans++;
- ans = ans % 1000000007;
- } else if (x - i > 0) {
- ans = ans + solve(x - i, dp);
- ans = ans % 1000000007;
- } else if (x - i < 0) {
- break;
- }
- }
- dp[x] = ans;
- return ans;
- }
- int main() {
- int n;
- cin >> n;
- vector<int> dp(n + 1, -1);
- ll answer = solve(n, dp);
- cout << answer;
- return 0;
- }
[text] dice combinations
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: