1. 程式人生 > 其它 >UVA11137 Ingenuous Cubrency【遞推】

UVA11137 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(= 213), 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 1 cube coins, or two 8 cube coin and five 1 cube coins.
在這裡插入圖片描述

Input
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.

Output
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
Sample Output
2
3
22
440022018293

問題連結UVA11137 Ingenuous Cubrency
問題簡述:(略)
問題分析:簡單的二叉搜尋樹問題,不解釋。

程式說明:(略)
參考連結:(略)
題記:(略)

AC的C++語言程式如下:

/* UVA11137 Ingenuous Cubrency */

#include <bits/stdc++.h>

using namespace std;

const int N = 10000;
long long dp[N];

int main()
{
    // Init;
    dp[0] = 1;
    for (int i = 1, p; (p = i * i * i) < N; i++)
        for (int j = p; j < N; j++)
            dp[j] += dp[j - p];

    int n;
    while(~scanf("%d", &n))
        printf("%lld\n", dp[n]);

    return 0;
}