日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hdu 3449 有依赖性的01背包

發(fā)布時間:2025/3/15 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu 3449 有依赖性的01背包 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目鏈接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3449

?

Consumer

?

Description

FJ is going to do some shopping, and before that, he needs some boxes to carry the different kinds of stuff he is going to buy. Each box is assigned to carry some specific kinds of stuff (that is to say, if he is going to buy one of these stuff, he has to buy the box beforehand). Each kind of stuff has its own value. Now FJ only has an amount of W dollars for shopping, he intends to get the highest value with the money.?

Input

The first line will contain two integers, n (the number of boxes 1 <= n <= 50), w (the amount of money FJ has, 1 <= w <= 100000) Then n lines follow. Each line contains the following number pi (the price of the ith box 1<=pi<=1000), mi (1<=mi<=10 the number goods ith box can carry), and mi pairs of numbers, the price cj (1<=cj<=100), the value vj(1<=vj<=1000000)?

Output

For each test case, output the maximum value FJ can get?

Sample Input

3 800 300 2 30 50 25 80 600 1 50 130 400 3 40 70 30 40 35 60

Sample Output

210


?

大意:在購買一類物品之前,必須買另一種物品。

本題是購買袋子,有體積,但是沒有價值。

AC代碼:

#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #define ll long long const int maxn=1e5+5; const int INF=0x3f3f3f3f;int dp[maxn]; int temp[maxn];int main() {int N,P;while(scanf("%d%d",&N,&P)==2){memset(dp,0,sizeof(dp));for(int i=1; i<=N; i++){int p,m;scanf("%d%d",&p,&m);memset(temp,-1,sizeof(temp));for(int k=p; k<=P; k++)temp[k]=dp[k-p];while(m--){int a,b;scanf("%d%d",&a,&b);for(int k=P; k>=a; k--)if(temp[k-a]!=-1)temp[k]=max(temp[k],temp[k-a]+b);}for(int k=1; k<=P; k++)dp[k]=max(dp[k],temp[k]);}printf("%d\n",dp[P]);}return 0; }

一個寫的好幾種方法的博客:http://www.cnblogs.com/wuyiqi/archive/2011/11/26/2264283.html

轉(zhuǎn)載于:https://www.cnblogs.com/a-clown/p/6040268.html

總結(jié)

以上是生活随笔為你收集整理的hdu 3449 有依赖性的01背包的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。