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块宝石,它的重量为 ...
随机推荐
- [MUD]MUDLIB详解/MUDOS运行流程/最小MUDLIB/mud文件结构
现在大部分中文MUD都是在东方故事(esII)基础上发展起来的,其目录结构基本一样, 也有个别MUD为了标新立异对个别目录换了个名字以示不同,但其实质没有什么变化. 这个做的最可恶的是xkx,把一个好 ...
- Oracle EBS-SQL (BOM-6):检查物料失效但BOM中未失效的数据.sql
select msi.segment1 装配件编码 , msi.description 装配件描述 , msi.item_type ...
- git多人协作
多人协作 当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了,并且,远程仓库的默认名称是origin. 要查看远程库的信息,用git remote: $ ...
- HDU 3037 Saving Beans(Lucas定理的直接应用)
解题思路: 直接求C(n+m , m) % p , 由于n , m ,p都非常大,所以要用Lucas定理来解决大组合数取模的问题. #include <string.h> #include ...
- Android的MVC框架
http://www.cnblogs.com/wanghafan/archive/2012/07/20/2600786.html MVC是当前比较流行的框架,随便Google下,就可以发现几乎所有的应 ...
- 【Android进阶学习】shape和selector的结合使用
shape和selector是Android UI设计中经常用到的,比如我们要自定义一个圆角Button,点击Button有些效果的变化,就要用到shape和selector.可以这样说,shape和 ...
- Objective C 链式调用
起因 某日使用DKChainableAnimationKit的时候发现可以如下写代码: view.animation.rotate(180).anchorTopLeft.thenAfter(1.0). ...
- css滤镜(转载)
STYLE="filter:filtername(fparameter1, fparameter2...)" (Filtername为滤镜的名称,fparameter1.fpara ...
- SQL学习之使用常用函数处理数据
一.在介绍使用函数处理数据前,先说下使用DBMS(数据库管理系统)处理数据所带来的问题! 1.与几乎所有的DBMS都同等的支持SQL语句(如SELECT)不同,每一个DBMS都有特定的函数,事实上,只 ...
- 七种Prolog解释器/编译器
http://blog.sina.com.cn/s/blog_494e45fe0100lh1v.html PROLOG 人工智能领域常用的语言,开发自然语言分析,专家系统,以及所有和智能有关的程序,都 ...