Advertisement
newb_ie

UVA - 11137

Jul 18th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1.  /*
  2.        _________
  3.       /         \
  4.      /  _     _  \
  5.     /   0     0   \
  6.    |       ||     |
  7.    |              | => HI
  8.     \     -----   /
  9.      \           /
  10.       \_ _ _ _ _/
  11.  */
  12.  
  13. #include<bits/stdc++.h>
  14. using namespace std;
  15. using lli = int64_t;
  16. const int maxN = 10100;
  17. int coins[] = {1,8,27,64,125,216,343,512,729,1000,1331,1728,2197,2744,3375,4096,4913,5832,6859,8000,9261};
  18. lli grid[21][maxN];
  19. lli solve(int idx,int n){
  20.     if(idx == 21 or n == 0){
  21.         return n == 0;
  22.     }
  23.     if(grid[idx][n] != -1){
  24.         return grid[idx][n];
  25.     }
  26.     lli res = 0;
  27.     for(int i = 0;i <= n; i++){
  28.         if(n - (i * coins[idx]) >= 0){
  29.             res += solve(idx + 1,n - (i * coins[idx]));
  30.         }else{
  31.             break;
  32.         }
  33.     }
  34.     return grid[idx][n] = res;
  35. }
  36. int main(){
  37.     ios::sync_with_stdio(false);
  38.     cin.tie(nullptr);
  39.     int n;
  40.     memset(grid,-1,sizeof(grid));
  41.     while(cin >> n and EOF){
  42.         cout << solve(0,n) << "\n";
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement