-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva11137.cpp
72 lines (45 loc) · 877 Bytes
/
uva11137.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <cstdio>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <limits.h>
#include <list>
using namespace std;
typedef long long int64;
int64 dp[25][10010];
int cube(int t)
{
return t*t*t;
}
int64 ways(int coin_index, int sum)
{
if(sum < 0)
return -1;
if(dp[coin_index][sum] != -1)
return dp[coin_index][sum];
if(sum == 0 || coin_index == 1)
return 1;
int64 count = 0;
if(ways(coin_index, sum - cube(coin_index)) > 0)
count += ways(coin_index, sum - cube(coin_index));
if(ways(coin_index - 1, sum) > 0)
count += ways(coin_index - 1, sum);
return dp[coin_index][sum] = count;
}
int main()
{
int sum;
memset(dp, -1, sizeof(dp));
while(true)
{
cin >> sum;
if(cin.eof())
break;
int64 rez = ways(21, sum);
cout << rez << endl;
}
return 0;
}