Advertisement
newb_ie

UVA - 11137

Jul 18th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 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.         }
  31.     }
  32.     return grid[idx][n] = res;
  33. }
  34. int main(){
  35.     ios::sync_with_stdio(false);
  36.     cin.tie(nullptr);
  37.     int n;
  38.     memset(grid,-1,sizeof(grid));
  39.     while(cin >> n and EOF){
  40.         cout << solve(0,n) << "\n";
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement