Uva--11137(动规)

2014-08-04 23:47:24

Problem I: Ingenuous Cubrency

People in Cubeland use cubic coins. Not only the unit of currency is called a cube but also the coins are shaped like cubes and their values are cubes. Coins with values of all cubic numbers up to 9261 (= 21 3), i.e., coins with the denominations of 1, 8, 27, ..., up to 9261 cubes, are available in Cubeland.

Your task is to count the number of ways to pay a given amount using cubic coins of Cubeland. For example, there are 3 ways to pay 21 cubes: twenty one 1 cube coins, or one 8 cube coin and thirteen 1cube coins, or two 8 cube coin and five 1 cube coins.

Input consists of lines each containing an integer amount to be paid. You may assume that all the amounts are positive and less than 10000.

For each of the given amounts to be paid output one line containing a single integer representing the number of ways to pay the given amount using the coins available in Cubeland.

Sample input

10 
21
77
9999

Output for sample input

2
3
22
440022018293

思路:简单的完全背包(变相的)。几个注意点:long long,dp[0]初值1,dp置零。
 1 /*************************************************************************
 2     > File Name: f.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com 
 5     > Created Time: Sun 03 Aug 2014 08:50:55 PM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <iostream>
13 #include <algorithm>
14 using namespace std;
15 #define ll long long
16 
17 int main(){
18     int sum;
19     int v[21];
20     ll dp[10005];
21     for(int i = 1; i <= 21; ++i)
22         v[i - 1] = i * i * i;
23     memset(dp,0,sizeof(dp));
24     dp[0] = 1;
25     for(int i = 0; i < 21; ++i){
26         for(int j = v[i]; j <= 10000; ++j){
27             dp[j] += dp[j - v[i]];
28         }
29     }
30     while(scanf("%d",&sum) == 1)
31         printf("%lld\n",dp[sum]);
32     return 0;
33 }

 


posted @ 2014-08-04 23:49  Naturain  阅读(180)  评论(0编辑  收藏  举报