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

Problem Description
The SDOI in 2045 is far from what it was been 30 years ago. Each competition has t minutes and n problems.

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.

 
Input
There is an positive integer T(T≤10) in the first line for the number of testcases.(the number of testcases with n>200 is no more than 5)

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.

 
Output
For each testcase output a line for an integer, for the highest mark dxy will get in this competition.
 
Sample Input
1
4 10
110 5 9
30 2 1
80 4 8
50 3 2
 
Sample Output
88
题解:01背包问题。。。不过要预处理下,按照分数流失度从大到小排;
代码:
 #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背包)的更多相关文章

  1. HDU 5501:The Highest Mark 01背包

    The Highest Mark  Accepts: 71  Submissions: 197  Time Limit: 2000/1000 MS (Java/Others)  Memory Limi ...

  2. 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 ...

  3. HDU 5501 The Highest Mark

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5501 The Highest Mark  Accepts: 32  Submissions: 193 ...

  4. hdu3448 01背包+dfs

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3448 Description 0/1 bag problem should sound f ...

  5. hdu 2955 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...

  6. nyoj 203 三国志 dijkstra+01背包

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=203 思路:先求点0到每个点的最短距离,dijkstra算法,然后就是01背包了 我奇怪的 ...

  7. noj [1479] How many (01背包||DP||DFS)

    http://ac.nbutoj.com/Problem/view.xhtml?id=1479 [1479] How many 时间限制: 1000 ms 内存限制: 65535 K 问题描述 The ...

  8. hdu 3449 (有依赖的01背包)

    依赖背包 事实上,这是一种树形DP,其特点是每个父节点都需要对它的各个儿子的属性进行一次DP以求得自己的相关属性. fj打算去买一些东西,在那之前,他需要一些盒子去装他打算要买的不同的物品.每一个盒子 ...

  9. [Usaco2007 Dec]宝石手镯[01背包][水]

    Description 贝茜在珠宝店闲逛时,买到了一个中意的手镯.很自然地,她想从她收集的 N(1 <= N <= 3,402)块宝石中选出最好的那些镶在手镯上.对于第i块宝石,它的重量为 ...

随机推荐

  1. CakePHP 2.x 升级3.0

    CakePHP 2.x => 3.x 升级手顺 一.Controller层 1.find('list') 原2.x中该方法通过指定option中的'fields'来实现key=>value ...

  2. ViewTreeObserver简介

    Android ViewTreeObserver简介 一.结构 public final class ViewTreeObserver extends Object java.lang.Object ...

  3. Jimmy Choo_百度百科

    Jimmy Choo_百度百科 Jimmy Choo

  4. APUE读书笔记-第14章-高级I/O

    14.1 引言 *高级I/O包括非阻塞I/O.记录锁.系统V流机制.I/O多路转换(select和poll函数).readv和writev函数以及存储映射I/O(mmap) 14.2 非阻塞I/O * ...

  5. winds引导配置数据文件包含的os项目无效

    我装了winds7与linux双系统,用easyBcd程序时,删除了一个winds7,之后winds7就进不去了, 进入winds7时显示winds未能启动,原因可能是最近更改了硬件或软件.解决此问题 ...

  6. 如何调试webservice接口是否正常

    soapui 调试webservice接口 1首先iis 部署网站 2添加webservice 3附加到进程调试  找w开头的 4然后request填充数据

  7. 跟我一起学写jQuery插件开发方法(转载)

    jQuery如此流行,各式各样的jQuery插件也是满天飞.你有没有想过把自己的一些常用的JS功能也写成jQuery插件呢?如果你的答案是肯定的,那么来吧!和我一起学写jQuery插件吧!     很 ...

  8. 全面修复IE,注册IE所有dll

    全面修复IE,注册IE所有dll 复制,粘贴到文本文档里,保存成.bat文件,双击运行. rundll32.exe advpack.dll /DelNodeRunDLL32 %systemroot%\ ...

  9. Infragistics的介绍以及在ASP.net中使用的总结

    Infragistics系列控件是一套很好,很强大的控件,.感觉很好..现在自己做项目也用..却发现网上没有一套中文的教程,中文资料都很少..在这里就把自己的研究心得写下来... 首先安装,一步一步装 ...

  10. mysql之数据库特性认识

    最近面试经常被面试官问道关于数据库方面的知识,于是总结一下面试官问的题以及自己对数据库的认识 1.之前百度面试官问了我一个特别基础的sql问题:如何清除表的所有记录,以前在学校做项目开发的时候有使用过 ...