Advertisement
Mirbek

ИГРАЛЬНЫЕ КОСТИ (с помощью динамики)

Feb 22nd, 2022
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 1e6 + 5;
  6. const int mod = 1e9 + 7;
  7.  
  8. int n;
  9. int dp[N];
  10.  
  11. int main(){
  12.     cin >> n;
  13.  
  14.     dp[0] = 1;
  15.  
  16.     for (int sum = 1; sum <= n; sum++) {
  17.         for (int x = 1; x <= 6; x++) {
  18.             if (x > sum) break;
  19.             dp[sum] = (dp[sum] + dp[sum - x]) % mod;
  20.         }
  21.     }
  22.  
  23.     cout << dp[n] << endl;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement