Advertisement
Josif_tepe

Untitled

Oct 20th, 2021
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int dp[1000000];
  5. const int MOD = 1e9 + 7;
  6. int p(int i){
  7.     if(i==0){
  8.     return 1;
  9.  
  10. }
  11. if(dp[i]!=-1){
  12.     return dp[i];
  13. }
  14. int result=0;
  15.  
  16. for(int j=1; j<=6; j++){
  17. if(i-j>=0){
  18. result+=p(i-j);
  19.     result %= MOD;
  20.  
  21. }
  22. }
  23. dp[i]=result;
  24. return result;
  25. }
  26.  
  27.  
  28. int main()
  29. {
  30.  
  31.     int n;
  32.     cin>>n;
  33.     for(int i=0; i<=n; i++){
  34.         dp[i]=-1;
  35.     }
  36.     cout<<p(n);
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement