博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 3033 I love sneakers! 分组背包
阅读量:5326 次
发布时间:2019-06-14

本文共 2103 字,大约阅读时间需要 7 分钟。

题目链接:

After months of hard working, Iserlohn finally wins awesome amount of scholarship. As a great zealot of sneakers, he decides to spend all his money on them in a sneaker store.

There are several brands of sneakers that Iserlohn wants to collect, such as Air Jordan and Nike Pro. And each brand has released various products. For the reason that Iserlohn is definitely a sneaker-mania, he desires to buy at least one product for each brand.

Although the fixed price of each product has been labeled, Iserlohn sets values for each of them based on his own tendency. With handsome but limited money, he wants to maximize the total value of the shoes he is going to buy. Obviously, as a collector, he won’t buy the same product twice.
Now, Iserlohn needs you to help him find the best solution of his problem, which means to maximize the total value of the products he can buy.

题意描述:有n个物品,多种品牌,每个产品有三个属性a,b和c,分别代表品牌种类、价钱和价值。现在你有现金m和k个伙伴,要求为每一位伙伴至少买一件物品,求出得到的最大价值(编号为u的伙伴只能得到品牌种类为u的物品)。

算法分析:分组背包。dp[i][j]代表前 i 种物品、身上有j元获得的最大价值。

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #define inf 0x7fffffff10 using namespace std;11 const int maxn=100+10;12 13 int n,m,k;14 int dp[12][10000+10];15 vector
> vec[maxn];16 17 int main()18 {19 while (scanf("%d%d%d",&n,&m,&k)!=EOF)20 {21 int a,b,c;22 for (int i=1 ;i<=n ;i++) vec[i].clear();23 for (int i=1 ;i<=n ;i++)24 {25 scanf("%d%d%d",&a,&b,&c);26 vec[a].push_back(make_pair(b,c));27 }28 memset(dp,-1,sizeof(dp));29 memset(dp[0],0,sizeof(dp[0]));30 int flag=0;31 // for (int i=1 ;i<=k ;i++)32 // {33 // int num=vec[i].size();34 // for (int j=0 ;j
=p ;j--)46 {47 48 int value=vec[i][u].second;49 if (dp[i][j-p]!=-1)50 dp[i][j]=max(dp[i][j],dp[i][j-p]+value);51 if (dp[i-1][j-p]!=-1)52 dp[i][j]=max(dp[i][j],dp[i-1][j-p]+value);53 }54 }55 }56 if (flag || dp[k][m]==-1) printf("Impossible\n");57 else printf("%d\n",dp[k][m]);58 }59 return 0;60 }

 

转载于:https://www.cnblogs.com/huangxf/p/4374198.html

你可能感兴趣的文章
总想对你表白
查看>>
BSGS算法及拓展
查看>>
读完《大道至简》后的小感悟
查看>>
聊聊工作和职业规划
查看>>
认清性能问题
查看>>
Linux:CentOS7.4新建用户并授权
查看>>
求a加到b二进制加法有多少次进位。
查看>>
Multiple Contexts have a path of "/xxxx"问题解决
查看>>
[cocos2dx笔记010]用于UI的事件管理器
查看>>
[DLX反复覆盖] hdu 2828 Lamp
查看>>
Response.Write页面跳转
查看>>
好的网页
查看>>
分享一个控制台版本《推箱子》小游戏,感兴趣的可以看看
查看>>
正则表达式之实战--员工信息表
查看>>
【bzoj3343】教主的魔法 分块+二分
查看>>
【bzoj3730】震波 动态点分治+线段树
查看>>
23种设计模式学习之享元模式
查看>>
dijkstra板子
查看>>
清空oracle session
查看>>
JNI崩溃调试
查看>>