The Highest Mark(01背包)
The Highest Mark
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 247 Accepted Submission(s): 101
The ith problem with the original mark of Ai(Ai≤106),and it decreases Bi by each minute. It is guaranteed that it does not go to minus when the competition ends. For example someone solves the ith problem after x minutes of the competition beginning. He/She will get Ai−Bi∗x marks.
If someone solves a problem on x minute. He/She will begin to solve the next problem on x+1 minute.
dxy who attend this competition with excellent strength, can measure the time of solving each problem exactly.He will spend Ci(Ci≤t) minutes to solve the ith problem. It is because he is so godlike that he can solve every problem of this competition. But to the limitation of time, it's probable he cannot solve every problem in this competition. He wanted to arrange the order of solving problems to get the highest mark in this competition.
For each testcase, there are two integers in the first line n(1≤n≤1000) and t(1≤t≤3000) for the number of problems and the time limitation of this competition.
There are n lines followed and three positive integers each line Ai,Bi,Ci. For the original mark,the mark decreasing per minute and the time dxy of solving this problem will spend.
Hint:
First to solve problem 2 and then solve problem 1 he will get 88 marks. Higher than any other order.
4 10
110 5 9
30 2 1
80 4 8
50 3 2
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#define MIN(x,y)(x<y?x:y)
#define MAX(x,y)(x>y?x:y)
const int INF=0x3f3f3f3f;
using namespace std;
struct Node{
int a,b,c;
void in(){
scanf("%d%d%d",&a,&b,&c);
}
friend bool operator <(Node a,Node b){
return a.b*b.c>a.c*b.b;
}
};
Node dt[];
int bag[];
int main(){
int T,n,t;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&t);
for(int i=;i<n;i++){
dt[i].in();
}
sort(dt,dt+n);
memset(bag,,sizeof(bag));
for(int i=;i<n;i++){
for(int j=t;j>=dt[i].c;j--){
bag[j]=MAX(bag[j],bag[j-dt[i].c]+dt[i].a-j*dt[i].b);
}
}
int max=;
for(int i=;i<=t;i++)max=MAX(max,bag[i]);
printf("%d\n",max);
}
return ;
}
明知道暴力肯定超时,还是写了下;
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#define MIN(x,y)(x<y?x:y)
#define MAX(x,y)(x>y?x:y)
const int INF=0x3f3f3f3f;
using namespace std;
int n,t,ans;
int vis[];
struct Node{
int a,b,c;
};
Node dt[];
void dfs(int time,int score){
if(time>t)return;
ans=MAX(ans,score);
for(int i=;i<n;i++){
if(vis[i])continue;
vis[i]=;
dfs(time+dt[i].c,score+dt[i].a-dt[i].b*(time+dt[i].c));
vis[i]=;
}
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&t);
for(int i=;i<n;i++){
scanf("%d%d%d",&dt[i].a,&dt[i].b,&dt[i].c);
}
memset(vis,,sizeof(vis));
ans=;
dfs(,);
printf("%d\n",ans);
}
return ;
}
The Highest Mark(01背包)的更多相关文章
- 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 背包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 ...
- hdu3448 01背包+dfs
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3448 Description 0/1 bag problem should sound f ...
- hdu 2955 01背包
http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...
- nyoj 203 三国志 dijkstra+01背包
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=203 思路:先求点0到每个点的最短距离,dijkstra算法,然后就是01背包了 我奇怪的 ...
- noj [1479] How many (01背包||DP||DFS)
http://ac.nbutoj.com/Problem/view.xhtml?id=1479 [1479] How many 时间限制: 1000 ms 内存限制: 65535 K 问题描述 The ...
- hdu 3449 (有依赖的01背包)
依赖背包 事实上,这是一种树形DP,其特点是每个父节点都需要对它的各个儿子的属性进行一次DP以求得自己的相关属性. fj打算去买一些东西,在那之前,他需要一些盒子去装他打算要买的不同的物品.每一个盒子 ...
- [Usaco2007 Dec]宝石手镯[01背包][水]
Description 贝茜在珠宝店闲逛时,买到了一个中意的手镯.很自然地,她想从她收集的 N(1 <= N <= 3,402)块宝石中选出最好的那些镶在手镯上.对于第i块宝石,它的重量为 ...
随机推荐
- 安装虚拟机VMWare时出现1021错误的解决办法
今天安装虚拟机(VMWare Workstation9.0),中途老是出现错误:Failed to create the requested registry key key installer er ...
- hdu 2222 Keywords Search ac自动机模板
题目链接 先整理一发ac自动机模板.. #include <iostream> #include <vector> #include <cstdio> #inclu ...
- 3D空间坐标系转换复习
模型坐标系:ModelSpace 即模型本身为中心 模型本身自己 世界坐标系:WorldSpace 世界坐标系 整个世界 视角坐标系: ViewSpace 眼睛看到的范 ...
- IE WebDriver 因保护模式无法启动的解决 (转载)
现在Win7 已经应用很多了,即使是最原始的Win7 也是IE8,最新的patch后,都升到了IE11 Win7下预装高版本IE的情况下,启动IE WebDriver可能会出现: org.openqa ...
- Android之Service与IntentService的比较
Android之Service与IntentService的比较 不知道大家有没有和我一样,以前做项目或者练习的时候一直都是用Service来处理后台耗时操作,却很少注意到还有个IntentServ ...
- OpenGL中glRotatef()函数究竟对矩阵做了什么
OpenGL中glRotatef()函数究竟对矩阵做了什么 我们知道OpenGL中维持着两套矩阵,一个是模型视图矩阵(model view matrix),另一个是投影矩阵(projection ma ...
- 加入收藏夹的js代码(求兼容chrome浏览器的代码)
从网上找了加入收藏夹的js代码,但不兼容chrome,不知道有没有兼容chrome的相关代码,希望有知道的告诉一下,谢谢! 代码如下 $("#id").click(function ...
- JS判断是否安装flash player及当前版本
function flashChecker() { var hasFlash = 0; //是否安装了flash var flashVersion = 0; //flash版本 if(document ...
- 达内TTS6.0课件oop_day02
- curl返回值写入内存的场景
直接上代码: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <cur ...