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 ...
随机推荐
- sizeToFit的用法和用途
最近有遇到过sizeToFit的方法,比较好奇,所以查了点资料 在官方文档中 - (void)sizeToFit; // calls sizeThatFits: with current view b ...
- 1.PhotoShop缩小图片的三种方式
先声明,本人不是高前端的,若有不当或者不合理的地方,还望前端爱好者多多指教.此处只是留作个人记录备忘. PS中有三种缩小 1.视图缩小,那方法很多缩放工具.Ctrl+"-",导航器 ...
- oracle-snapshot too old 示例
一.快照太老例子: 1.创建一个很小的undo表空间,并且不自动扩展. create undo tablespace undo_small datafile '/u01/app/oracl ...
- 用JS实现版面拖拽效果
类似于这样的一个版面,点击标题栏,实现拖拽效果. 添加onmousedown事件 通过获取鼠标的坐标(clientX,clientY)来改变面板的位置 注意:面板使用绝对定位方式,是以左上角为参考点, ...
- javascript——事件处理
<script type="text/javascript"> function EventUtil() { var _self = this; ///添加事件 var ...
- wordpress version
version info /readme.html /wp-includes/version.php remove copyright 1.wp-login.php //<h1><a ...
- c# winfrom 委托实现窗体相互传值
利用委托轻松实现,子窗体向父窗体传值. 子窗体实现代码: //声明委托 public delegate void MyDelMsg(string msg); //定义一个委托变量 public MyD ...
- PHP面向对象(OOP):__toString()方法
我们前面说过在类里面声明“__”开始的方法名的方法(PHP给我们提供的),都是在某一时刻不同情况下自动调用执行的方 法,“__toString()”方法也是一样自动被调用的,是在直接输出对象引用时自动 ...
- 那些年被我坑过的Python——道阻且长(第五章实用模块讲解)
random模块 我的随机验证吗程序: 首先保证了字母和数字出现的概率是50% VS 50%,其次是可以订制输出多少位 def Captcha(size): Captcha_list = [] for ...
- 【C语言】结构组成(函数、语句、注释)
C语言结构组成 一.相关基础知识 二.具体内容 C语言由函数.语句和注释三部分组成: )函数与主函数: 一个C语言源程序可以由一个或多个源文件组成,每个源文件可由一个或多个函数组成,一个源程序 ...