I love sneakers!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2884    Accepted Submission(s): 1180 
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
 

Source
 

Recommend
gaojie
// dp 我将其按 鞋子牌子分类 ,然求 在至少有 i 种 牌子鞋子时,花 m 元钱最大可以达到的 价值  
#include <iostream>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
int
rb[][],rc[][];
int
dp[],dp_num[],dpy[]; int main()
{

int
N,M,K;
while
(scanf("%d %d %d",&N,&M,&K)!=EOF){
int
i,j,k;
int
x,y,z;
for
(i=;i<=;i++) rb[i][]=;
for
(i=;i<=N;i++)
{
scanf("%d %d %d",&x,&y,&z);
rb[x][++rb[x][]]=y;
rc[x][rb[x][]]=z; }
memset(dp,,sizeof(dp));
memset(dp_num,,sizeof(dp_num));
memset(dpy,,sizeof(dpy));
for
(i=;i<=K;i++){ int num=rb[i][];
for
(j=;j<=num;j++){
for
(k=M;k>=rb[i][j];k--){
if
(dpy[k]<dp[k-rb[i][j]]+rc[i][j]&&dp_num[k-rb[i][j]]>=i-)
{

dpy[k]=dp[k-rb[i][j]]+rc[i][j];
dp_num[k]=i;
}

else if
(dp_num[k]==i-&&dp_num[k-rb[i][j]]==i-){
dpy[k]=dp[k-rb[i][j]]+rc[i][j];
dp_num[k]=i;
} }

// printf("%d\n",dpy[M]);
for(k=;k<=M;k++)//这里需要同种鞋子确保更新被用到了
if(dpy[k]>dp[k])
dp[k]=dpy[k];
}

for
(k=;k<=M;k++)//这里确保 在有用了i种牌子时记录了结果
dp[k]=dpy[k]; }
// printf("%d\n",dp[M]);
for(i=M;i>=;i--)
if
(dp_num[i]==K)
break
;
if
(i>=)
printf("%d\n",dp[i]);
else

printf("Impossible\n");
}
return;
}

hdu 3033 I love sneakers!的更多相关文章

  1. [HDU 3033] I love sneakers! (动态规划分组背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3033 题意:给你K种品牌,每种品牌有不同种鞋,现在每种品牌至少挑一款鞋,问获得的最大价值,如果不能每种 ...

  2. hdu 3033 I love sneakers! 分组背包

    I love sneakers! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. hdu 3033 I love sneakers!(分组背包+每组至少选一个)

    I love sneakers! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. HDU 3033 I love sneakers! 我爱运动鞋 (分组背包+01背包,变形)

    题意: 有n<=100双鞋子,分别属于一个牌子,共k<=10个牌子.现有m<=10000钱,问每个牌子至少挑1双,能获得的最大价值是多少? 思路: 分组背包的变形,变成了相反的,每组 ...

  5. HDU 3033 组合背包变形 I love sneakers!

    I love sneakers! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...

  6. HDU 3033 分组背包变形(每种至少一个)

    I love sneakers! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. hdu 3033(好题,分组背包)

    I love sneakers! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. 【HDOJ】3033 I love sneakers!

    分组背包. #include <stdio.h> #include <string.h> #define mymax(a, b) (a>b) ? a:b typedef ...

  9. 【HDU】I love sneakers!(分组背包)

    看了许多的题解,都有题目翻译,很不错,以后我也这样写.直接翻译样例: /*鞋子的数量N[1, 100]; 拥有的金钱M[1, 1w]; 品牌数目[1, 10]*/ /*以下四行是对于每双鞋的描述*/ ...

随机推荐

  1. IEtester不靠谱

    对于刚刚学习前端的人来说,IEtester无疑是个测试神器, 刚开始用的时候,真有种如获至宝的兴奋. 然而,随着你学习的深入,你会慢慢地发现这个东西不太靠谱,而且会觉得没必要用它.为什么这么说呢? 首 ...

  2. 2015-4-2的阿里巴巴笔试题:乱序的序列保序输出(bit数组实现hash)

    分布式系统中的RPC请求经常出现乱序的情况.写一个算法来将一个乱序的序列保序输出.例如,假设起始序号是1,对于(1, 2, 5, 8, 10, 4, 3, 6, 9, 7)这个序列,输出是:123, ...

  3. 【转】perl中尖括号运算符(<>)使用说明

    perl中尖括号运算符的用途分享,这里简单介绍下,方便需要的朋友 perl中<>运算符可以有如下的用途: 1)如果尖括号中间是文件句柄,尖括号运算符允许你读取文件句柄,比如<STDI ...

  4. ASP.NET 页面传值得9种方式

    1. Get(即使用QueryString显式传递)     方式:在url后面跟参数.     特点:简单.方便.     缺点:字符串长度最长为255个字符:数据泄漏在url中.     适用数据 ...

  5. pl/sql插入报错

    用pl/sql 命令的方法导入文件,发现一只提示文件报错.报Error reading file错误. 原来: 在pl/sql工具->导入表里的sql插入方式下,可以选择“使用命令窗口”和“使用 ...

  6. 灵光乍现,lua数据绑定

    MVVM的核心就是数据驱动,数据驱动的核心就是数据绑定. 我一直在思考,如何使用lua做一个数据绑定的功能,仔细思考一下,数据绑定需要做到的功能很简单,就是当一个数据改变时,能主动回调一个或多个函数就 ...

  7. 【NHibernate】HQL入门

    在NHibernate 中 HQL 可以帮我们转成最终依赖数据库的查询脚本: 语法也甚是强大,适配主流数据库, HQL不支持union,要想取多个表数据可以做两次单独查询. IQuery query ...

  8. 【学习总结】【多线程】 线程 & 进程 & NSThread(多线程的一套API)

    一.进程和线程 1.什么是进程 进程是指在系统中正在运行的一个应用程序 每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内 比如同时打开 Chrome.Xcode,系统就会分别启动2个进 ...

  9. poi导出到excel步骤分析

    在没用过poi之前感觉poi是很高大上的样子, 项目中用了发现poi的代码重复性很高类似于jdbc的模板代码, 项目中如果大量使用最好封装起来; 总结一下归结为6步 1 打开或新创建一个工作薄(使用H ...

  10. play2 控制台打印乱码问题

    修改 play安装目录下,framework/build.bat java -Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:Ma ...