HD Piggy-Bank完全背包
生活随笔
收集整理的這篇文章主要介紹了
HD Piggy-Bank完全背包
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include <stdio.h>
#include <string.h>
#define min(a,b) a<b? a:b
int dp[1000005];
int main()
{int t;scanf("%d",&t);while(t--){memset(dp, 99898,sizeof(dp)); //注意初始化數組這里dp[0]=0;//首先這里要是零int e, f, n,w,c;scanf("%d%d", &e, &f);int v=f-e;scanf("%d", &n);while(n--){scanf("%d%d", &w, &c);for(int i = c; i<=v; i++)dp[i]=min(dp[i], dp[i-c]+w); //其實裝不滿時就沒被放進來的}if(dp[v]!=dp[v+1])printf("The minimum amount of money in the piggy-bank is %d.\n",dp[v]);elseputs("This is impossible.");}return 0;
}
這個博客里面說的很清楚點擊打開鏈接
總結
以上是生活随笔為你收集整理的HD Piggy-Bank完全背包的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 动态规划之01 背包---Hd2602
- 下一篇: strstr的应用---Hd 2054