博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDOJ_ACM_I love sneakers!
阅读量:6967 次
发布时间:2019-06-27

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

Problem Description
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.
 
Input
Input contains multiple test cases. Each test case begins with three integers 1<=N<=100 representing the total number of products, 1 <= M<= 10000 the money Iserlohn gets, and 1<=K<=10 representing the sneaker brands. The following N lines each represents a product with three positive integers 1<=a<=k, b and c, 0<=b,c<100000, meaning the brand’s number it belongs, the labeled price, and the value of this product. Process to End Of File.
 
Output
For each test case, print an integer which is the maximum total value of the sneakers that Iserlohn purchases. Print "Impossible" if Iserlohn's demands can’t be satisfied.
 
Sample Input
5 10000 31 4 62 5 73 4 991 55 772 44 66
 
Sample Output
255
 

分组背包

1<=N<=100 产品数
1<=M<=10000 钱
1<=K<=10 品牌数
1<=a<=k, b and c, 0<=b,c<100000 a是品牌数,b是价格,c是价值
第i行上的各个值是加入第i个品牌后实现的最大效益。
值得注意的是,这第i行的各个值都是经过第i个品牌的种类个数次得到的。
以f(i, j)为例
如果,第i个品牌的产品一个都还没放进去了,
那么f(i, j)可以是其他第i-1个品牌的最大效益+放入这个品牌的这个种类的效益
当然,这样还没完,还得与原来这个值进行比较,总之取大值
如果,第i个品牌的产品已经有放进去了,那么还可以有另一种途径得到这个值
那就是这i品牌,买多个种类的,看哪个大,就取哪个

思路-----只需看这里就行了

因为每个品牌有多种种类,所以你用一般的方法可以得到矩阵的每一行,
又考虑到每个品牌只能买一次,所以,除非是第一次,要不然你每个品牌的第一个物品都得买
如果到最后,即使是每个品牌的最便宜的都买不起,那就输出impossible了

编程

对于这个大矩阵,应该有10行,10000列
在来几个矩阵,用来存放每个品牌中种类的价格和价值,显然得需要两个矩阵,都是10行,100列
如价格矩阵a[i][j], 表示第i个品牌,第j个种类的价格

Code
View Code
Key Points
Firsly, you must clear your mind.
Secondly, don't forget to initilize every time.

转载于:https://www.cnblogs.com/chuanlong/archive/2012/11/26/2790032.html

你可能感兴趣的文章
酷!新款 iPad 可能将会取消 Home 键
查看>>
收快递成“新开门七件事” 京东小哥最暖心
查看>>
AMD又有大动作!2018CES期间牵手京东强势吸睛
查看>>
2017百度AI开发者大会 一场5000名开发者的分享盛宴
查看>>
野心外漏?Windows Defender或将独霸杀毒软件市场?
查看>>
重庆“90后”双胞胎“动妹” 守护春运回家路
查看>>
电影《蓝色生死恋》将上映 保留原版经典片段
查看>>
“中华龙乡”重庆铜梁举办首届中华龙灯艺术节
查看>>
探访广铁深圳“父女搭档”乘警出勤风采
查看>>
6月Python热文Top10,精选自1000篇文章
查看>>
Vue 折腾记 - (12) Nuxt.js写一个校验访问浏览器设备类型及环境的中间件
查看>>
使用 React 全家桶搭建一个后台管理系统
查看>>
腾讯云容器团队内部Istio专题分享
查看>>
当我说要做大数据工程师时他们都笑我,直到三个月后……
查看>>
【数据科学系统学习】Python # 数据分析基本操作[二] pandas
查看>>
第一批95后已经是阿里科学家了
查看>>
第七章: ansible故障排查
查看>>
everything is object
查看>>
Android中的设计模式之单例模式
查看>>
webpack核心概念
查看>>