2015暑假多校联合---CRB and His Birthday(01背包)
题目链接
http://acm.split.hdu.edu.cn/showproblem.php?pid=5410
She went to the nearest shop with M Won(currency unit).
At the shop, there are N kinds of presents.
It costs Wi Won to buy one present of i-th kind. (So it costs k × Wi Won to buy k of them.)
But as the counter of the shop is her friend, the counter will give Ai × x + Bi candies if she buys x(x>0) presents of i-th kind.
She wants to receive maximum candies. Your task is to help her.
1 ≤ T ≤ 20
1 ≤ M ≤ 2000
1 ≤ N ≤ 1000
0 ≤ Ai, Bi ≤ 2000
1 ≤ Wi ≤ 2000
The first line contains two integers M and N.
Then N lines follow, i-th line contains three space separated integers Wi, Ai and Bi.
CRB's mom buys 10 presents of first kind, and receives 2 × 10 + 1 = 21 candies.
- #include <iostream>
- #include <algorithm>
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- #define eps 1e-8
- #define maxn 105
- #define inf 0x3f3f3f3f3f3f3f3f
- #define IN freopen("in.txt","r",stdin);
- using namespace std;
- int dp[];
- int vis[][];
- int kind[][];
- int main()
- {
- int T;
- int M,N;
- cin>>T;
- while(T--)
- {
- scanf("%d%d",&M,&N);
- for(int i=;i<N;i++)
- scanf("%d%d%d",&kind[i][],&kind[i][],&kind[i][]);
- memset(dp,,sizeof(dp));
- memset(vis,,sizeof(vis));
- for(int i=;i<=M;i++)
- {
- int flag=-;
- for(int j=;j<N;j++)
- {
- if(i<kind[j][]) continue;
- int s=dp[i-kind[j][]]+kind[j][];
- if(!vis[i-kind[j][]][j]) s+=kind[j][];
- if(dp[i]<s)
- {
- dp[i]=s;
- flag=j;
- }
- }
- if(flag>=)
- {
- for(int j=;j<N;j++)
- {
- vis[i][j]=vis[i-kind[flag][]][j];
- }
- vis[i][flag]++;
- }
- }
- int tmp=;
- for(int i=;i<=M;i++)
- tmp=max(tmp,dp[i]);
- printf("%d\n",tmp);
- }
- return ;
- }
2015暑假多校联合---CRB and His Birthday(01背包)的更多相关文章
- 2015暑假多校联合---Zero Escape(变化的01背包)
题目链接 http://acm.hust.edu.cn/vjudge/contest/130883#problem/C Problem Description Zero Escape, is a vi ...
- 2015暑假多校联合---Expression(区间DP)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5396 Problem Description Teacher Mai has n numb ...
- 2015暑假多校联合---Mahjong tree(树上DP 、深搜)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5379 Problem Description Little sun is an artis ...
- 2015暑假多校联合---Cake(深搜)
题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...
- 2015暑假多校联合---Friends(dfs枚举)
原题链接 Problem Description There are n people and m pairs of friends. For every pair of friends, they ...
- 2015暑假多校联合---Assignment(优先队列)
原题链接 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbere ...
- 2015暑假多校联合---Problem Killer(暴力)
原题链接 Problem Description You are a "Problem Killer", you want to solve many problems. Now ...
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- 2016暑假多校联合---Windows 10
2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...
随机推荐
- 《JAVA 从入门到精通》 - 正式走向JAVA项目开发的路
以前很多时候会开玩笑,说什么,三天学会PHP,七天精通Nodejs,xx天学会xx ... 一般来说,这样子说的多半都带有一点讽刺的意味,我也基本上从不相信什么快速入门.我以前在学校的时候自觉过很多门 ...
- iOS-国家气象局-天气预报接口等常用接口
接口地址: http://www.weather.com.cn/data/sk/101010100.html http://www.weather.com.cn/data/cityinfo/10101 ...
- 防止SQL注入的,网站安全的一些常用解决方案
--------------------------------------------------------过滤URL中的一些特殊字符,动态SQL语句使用PrepareStatement.. -- ...
- mysql创建数据库指定编码uft8
mysql创建数据库指定编码uft8 CREATE DATABASE IF NOT EXISTS my_db default character set utf8 COLLATE utf8_gener ...
- Constraint1:主键约束,唯一性约束和唯一索引
1,主键约束创建索引 作为Primay Key的列是唯一的,非空的,Sql Server在创建主键约束时,自动为主键列创建一个唯一索引,并且索引列不允许为null. create table dbo. ...
- java中有关线程的题目
1,看一下下面程序错误发生在哪一行! class Test implements Runnable{ public void run(Thread t){ } } 2,输出结果是什么? class T ...
- maven -- 学习笔记(四)实现在Eclipse用maven搭建springmvc项目(附构建步骤和详细实现代码)
Learn from:http://www.cnblogs.com/fangjins/archive/2012/05/06/2485459.html,感谢楼主的分享,才有下面的这篇学习小结 一.环境准 ...
- SharePoint Server 2013开发之旅(一):新的开发平台和典型开发场景介绍
我终于开始写这个系列文章,实际上确实有一段时间没有动笔了.最近重新安装了一套SharePoint Server 2013的环境,计划利用工作之余的时间为大家写一点新的东西. SharePoint Se ...
- c#连接mysql环境配置
写.net的时候一直用的都是sql sever,mysql小 有命令行方便就想试了一下,网上搜很久,下载很多配置文件都不成功.昨晚上搞到两点多,冒着生命危险. 后来终于在一个网站上找到这个 MySQL ...
- Struts2整合Hibernate3实现用户登录功能
所用技术:struts2 ,hibernate,jsp,mysql 本DEMO仅仅实现用户登录功能,采用MVC思想,自己也觉得相对是比较简单,比较容易理解数据流向的一个例子,通过整合这个过程,能够清晰 ...