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块宝石,它的重量为 ...
随机推荐
- codeforces 645C . Enduring Exodus 三分
题目链接 我们将所有为0的位置的下标存起来. 然后我们枚举左端点i, 那么i+k就是右端点. 然后我们三分John的位置, 找到下标为i时的最小值. 复杂度 $ O(nlogn) $ #include ...
- 初识C(2)---从printf函数开始
继承[K&R]的传统,我们的第一个C语言程序也是“Hello, World.”. 书写C语言程序的大前提:C语言中的语法符号必须都是英文字符,即在中文输入法关闭状态下输入的字符. 例 1. H ...
- A类型物料必须为装配拉式,供应子库为B仓
应用 Oracle Bill Of Materiel 层 Level Function 函数名 Funcgtion Name MT_BOMFDBOM 表单名 Form Name BOMFDBOM ...
- [LeetCode][Python]Palindrome Number
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/palindr ...
- openstack 开发step-by-step
Set up your Open Stack There are several ways to deploy openstack, Devstack is easily for developer ...
- powerpc e500系列,linux初始化的tlb汇编,添加人肉代码注释
powerpc e500的内核启动,关于tlb的初始化可以说是重头戏.看懂这段代码后,powerpc的虚实映射基本不在话下. 这段初始化tlb要考虑的,主要是将boot可能初始化过的tlb全清零,然后 ...
- [置顶] C# WINCE调节屏幕亮度
在wince里面保存屏幕亮度的值保存在注册表HKEY_CURRENT_USER\ControlPanel\\Backlight\Brightness里面,值的范围是0-100,所以要改变屏幕的亮度,只 ...
- Crisis of HDU(母函数)
Crisis of HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 许士彦:创业不走寻常路 APP最好时间已过
从用户体验服务设计公司eico design到拥有两千多万用户的独立微博客户端Weico,再到备受欢迎的影像APP(微可拍,Weico Gif),Weico团队走过了一条不寻常的创业之路. 作为一家新 ...
- dom4j和jaxp解析工具的
dom4j解析中的几个对象 node --branch --document --element --commment --attribute --text branch --document --e ...