HDU 5501 背包问题
需要按照B/C的值从大到小排序。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9+;
const int maxn = ;
const int MOD = ; int A[maxn], B[maxn], C[maxn];
int dp[];
int vis[maxn]; struct node
{
int A, B, C;
bool friend operator < (node a, node b)
{
return 1.0*a.B/a.C > 1.0*b.B/b.C;
}
}P[maxn]; int main()
{
int T;
scanf("%d", &T); while(T--)
{
int n, t;
scanf("%d %d", &n, &t);
for(int i=; i<=n; i++)
scanf("%d %d %d", &P[i].A, &P[i].B, &P[i].C); sort(P+, P+n+);
memset(dp, , sizeof(dp)); for(int i=; i<= n; i++)
vis[i] = INF; for(int i=; i<=n; i++)
{
for(int j=t; j>=P[i].C; j--)
dp[j] = max(dp[j], dp[j-P[i].C] + P[i].A - P[i].B*j);
} int ans = ;
for(int i=; i<= t; i++)
ans = max(ans, dp[i]); printf("%d\n", ans);
}
return ;
}
/*
1
2 10
110 5 9
30 2 1
*/
HDU 5501 背包问题的更多相关文章
- HDU 5501 The Highest Mark 背包dp
The Highest Mark Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- HDU 5501 The Highest Mark
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5501 The Highest Mark Accepts: 32 Submissions: 193 ...
- hdu 2126背包问题
/*有n件物品,旅客一共有m块大洋.第一个问题,旅客最多可以买多少件物品?请注意,这里是多少件,不是价值最大.所以这个非常好求,将所有的物品按照价值排序,先买便宜的,再买贵的.贪心的思想.这个地方有些 ...
- HDU 1203 背包问题
题目大意: 根据学校的申请费用,根据已有的钱得到最大的offer率 这里很明显就是一个价值为概率的背包问题 计算两个offer合并的概率 为a + b - a*b #include <cstdi ...
- HDU 5501:The Highest Mark 01背包
The Highest Mark Accepts: 71 Submissions: 197 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- hdu 5501 The Highest Mark(贪心+01背包)
题意:类似cf的赛制,每道题目有A,B,C三个值,A表示初始分数,B表示每分钟题的分数会减少B,C表示做这道题需要C分钟,数据保证分数不会变为负数.现在给出比赛时长,问安排做题的顺序,求最大得分. 思 ...
- ACboy needs your help hdu 分组背包问题
Description ACboy has N courses this term, and he plans to spend at most M days on study.Of course,t ...
- bone collector hdu 01背包问题
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...
- HDU 5501——The Highest Mark——————【贪心+dp】
The Highest Mark Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
随机推荐
- 关于oracle的函数,存储过程,触发器,序列,视图,左右连接一些的应用 带案例
CREATE TABLE STUDENT( --创建学生表 ID NUMBER(10) PRIMARY KEY, --主键ID NAME VARCHAR2(20), CLASSNAME VA ...
- windows10UWP:如何判断一个文件或者文件夹是否存在?
使用 StorageFolder.TryGetItemAsync 方法,尝试按名称获取文件或文件夹,不需将错误捕捉逻辑添加到代码(就像使用 StorageFolder.GetItemAsync 一样) ...
- LTP 分词算法实践
参考链接: https://github.com/HIT-SCIR/ltp/blob/master/doc/install.rst http://www.xfyun.cn/index.php/serv ...
- 浮点数精确表示,java陷阱
/** 浮点数表示问题 @author husky */ public class Change { public static void main(String[] args) { double n ...
- Windows2003 下 MySQL 数据库每天自动备份
1. 环境: windows server 2003 + Apache 2.0 + PHP5 + MySQL 4.0.26 . 2. 假设 PHP 安装目录为 D:/php ,MySQL 安装目录为 ...
- javascript——闭包
<script type="text/javascript"> //什么是闭包: //是指语法域位于某个特定的区域,具有持续参照(读写)位于该区域内自身范围之外的执行域 ...
- js submit的問題
form 里面有input name="submit"的时候 $('#seachform').submit();不起作用
- 【JQuery学习历程】2.JQuery选择器
基本选择器 选择器 描述 返回 示例 #id 根据给定的id匹配元素 单个元素 $("#myId") .class 根据给定的class类匹配元素 集合元素 $(".my ...
- Trigger model Trigger expr_id in WorkFolow
For example, suppose you want to set a Sale Order into the state "Done" once it has been s ...
- ios CAF音频转换为MP3
Url:http://blog.csdn.net/ysy441088327/article/details/7392842#reply 为了达到 iPhone 与 Android 实现音频互通. 那么 ...