hdu2063investment题解(完全背包)

原创 2016年05月30日 22:59:53

这道题需要一个小技巧,由于所有的value都是multiple of 1000,所以将总钱数除以1000,每个value除以1000,将dp数组的大小降下来
状态转移方程:
dp[k]=Max(dp[k-bond1[j]]+bond2[j],dp[k]);

#include <stdio.h>
#include <string.h>
#define bttm 1000
#define M(X,Y) ((X)>(Y)?(X):(Y))
int bond1[12];
int dp[50050],bond2[12];
int main(int argc, char const *argv[])
{
    int N,amnt,yr,i,num,j,k,tmp;
    scanf("%d",&N);
    while(N--)
    {
        scanf("%d %d",&amnt,&yr);
        scanf("%d",&num);
        for(i=0;i<num;i++)
        {
            scanf("%d %d",bond1+i,bond2+i);
            bond1[i]/=bttm;
        }
        for(i=0;i<yr;i++)
        {
            tmp=amnt/bttm;
            memset(dp,0,sizeof(dp));
            for(j=0;j<num;j++)
                {
                    for(k=bond1[j];k<=tmp;k++)
            dp[k]=M(dp[k-bond1[j]]+bond2[j],dp[k]);
                }
            amnt+=dp[tmp];
        }
        printf("%d\n",amnt);
    }
    return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

HDU2063:Investment(完全背包)

Description John never knew he had a grand-uncle, until he received the notary's letter. He learned...

poj2063 & hdu1963 Investment 又是DP啦,,经典完全背包问题

John never knew he had a grand-uncle, until he received the notary's letter. He learned that his lat...

HDU 2063 Investment 完全背包

Description John never knew he had a grand-uncle, until he received the notary's letter. He learn...

HDU2063:Investment-wust9(完全背包典型)

Problem C Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tot...

POJ 2063 Investment 完全背包

点击打开链接 Investment Time Limit: 1000MS   Memory Limit: 30000K Total Submiss...

poj2063Investment【完全背包】

Language: Default Investment Time Limit: 1000MS   Memory Limit: 30000K Total Sub...

POJ2063 Investment(完全背包)

题意: 买债券,总共n种债券,分别给出价格和收益,给出本金和年数,每年的本金都会改变,问最后本金加收益的和 要点: 很明显的完全背包问题,只要每次改变本金就可以,但这里有个问题就是数目过大,直接...

POJ 2063 - Investment(完全背包)

Description John never knew he had a grand-uncle, until he received the notary's letter. He learn...

POJ2063 Investment (完全背包)

Investment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 9760 Accepted: 3398...

(完全背包)Investment(P2063)

#include #include #include #include #include #include #include #include #include #include #include #...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)