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. php 输出带变量字符串

    (一) <?php $a=50;echo "Hello World 我有"."$a"."元";?> 看此例子,变量a的输出,在p ...

  2. IOS版新闻客户端应用源码项目

    IOS版新闻客户端应用源码,这个是一款简单的新闻客户端源码,该应用实现没采用任何第三方类库的 ,并且这个应用的UI做得很不错的,值得我们的参考和学习,希望大家可以更加完善这款新闻类的应用吧. 源码下载 ...

  3. 走进C标准库(7)——"string.h"中函数的实现memcmp,memcpy,memmove,memset

    我的memcmp: int memcmp(void *buf1, void *buf2, unsigned int count){ int reval; while(count && ...

  4. 从源码看Android中sqlite是怎么通过cursorwindow读DB的

    更多内容在这里查看 https://ahangchen.gitbooks.io/windy-afternoon/content/ 执行query 执行SQLiteDatabase类中query系列函数 ...

  5. UltraISO制作U盘系统安装盘(图文教程)

    虽然现在的系统盘做的越来越傻瓜化,安装方法也非常多,但是仍然时常有朋友询问怎么安装系统,特别是没有刻录机或不想刻盘,又不懂硬盘安装的朋友,这里特别介绍一种用U盘来安装系统的方法,非量产,量产因U盘芯片 ...

  6. 07.20 html5的适配flexible

    <script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js"> ...

  7. iOS开发基本须要

        iOS开发基本须要 1 准备好对应的硬件和软件配置------基于Intel处理器的Mac操作系统 2 具有C++,Java或其它面向对象编程语言的开发经验 3 最新的iphone SDK的下 ...

  8. stl之map 排序

    排序问题,STL中默认是采用小于号来排序的,因为设置int等类型做key,它本身支持小于号运算,在一些特殊情况,比如关键字是一个结构体,涉及到排序就会出现问题,因为它没有小于号操作,insert等函数 ...

  9. javaScript操作select

    注意:Option中的O是要大写的,不然语法报错 1.动态创建select       function createSelect(){ var mySelect = document.createE ...

  10. Sublime Text 3:3114的安装(目前最新),插件emmet的安装

    随便一些好了. 直接英文版吧,建议不要找中文版,学习英语不是? https://www.sublimetext.com/3   下载 https://github.com/wbond/package_ ...