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 3
1 4 6
2 5 7
3 4 99
1 55 77
2 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.
posted on 2012-11-26 23:04  MrMission  阅读(213)  评论(0编辑  收藏  举报