hdu1028 划分数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu1028 划分数相关的知识,希望对你有一定的参考价值。

  题意是将一个整数N划分成不超过N个整数的和, 我们定义d[i][j]为j划分成不超过i个整数的和的方案数, 那么d[i][j] = d[i][j-i](全大于0) + d[i-1][j](不全大于0)。 答案就是d[N][N], 代码如下:

#include <iostream>
#include <algorithm>

using namespace std;
typedef long long LL;
LL d[150][150];

int main()
{
    d[0][0] = 1;
    for(int i=1; i<=120; i++) d[i][0] = 1;
    for(int i=1; i<=120; i++)
        for(int j=1; j<=120; j++)
        {
            d[i][j] = d[i-1][j];
            if(j-i>=0)
                d[i][j] += d[i][j-i];
        }
    int N;
    while(cin>>N)
    {
        cout<<d[N][N]<<endl;
    }
    return 0;
}

 

以上是关于hdu1028 划分数的主要内容,如果未能解决你的问题,请参考以下文章

HDU 1028 Ignatius and the Princess III dp

HDU 1028 整数划分问题 DP

hdu 1028 整数的划分问题

HDU 1028 Ignatius and the Princess III 整数的划分问题(打表或者记忆化搜索)

hdu 1028题解

hdu1028