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

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背包问题。。。不过要预处理下,按照分数流失度从大到小排;

代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 #include<queue>
 5 #define MIN(x,y)(x<y?x:y)
 6 #define MAX(x,y)(x>y?x:y)
 7 const int INF=0x3f3f3f3f;
 8 using namespace std;
 9 struct Node{
10     int a,b,c;
11     void in(){
12         scanf("%d%d%d",&a,&b,&c);
13     }
14     friend bool operator <(Node a,Node b){
15         return a.b*b.c>a.c*b.b;
16     }
17 };
18 Node dt[1010];
19 int bag[3010];
20 int main(){
21     int T,n,t;
22     scanf("%d",&T);
23     while(T--){
24         scanf("%d%d",&n,&t);
25         for(int i=0;i<n;i++){
26             dt[i].in();
27         }
28         sort(dt,dt+n);
29         memset(bag,0,sizeof(bag));
30         for(int i=0;i<n;i++){
31             for(int j=t;j>=dt[i].c;j--){
32                 bag[j]=MAX(bag[j],bag[j-dt[i].c]+dt[i].a-j*dt[i].b);
33             }
34         }
35         int max=0;
36         for(int i=0;i<=t;i++)max=MAX(max,bag[i]);
37         printf("%d\n",max);
38     }
39     return 0;
40 }

明知道暴力肯定超时,还是写了下;

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 #include<queue>
 5 #define MIN(x,y)(x<y?x:y)
 6 #define MAX(x,y)(x>y?x:y)
 7 const int INF=0x3f3f3f3f;
 8 using namespace std;
 9 int n,t,ans;
10 int vis[1010];
11 struct Node{
12     int a,b,c;
13 };
14 Node dt[1010];
15 void dfs(int time,int score){
16     if(time>t)return;
17     ans=MAX(ans,score);
18     for(int i=0;i<n;i++){
19         if(vis[i])continue;
20         vis[i]=1;
21         dfs(time+dt[i].c,score+dt[i].a-dt[i].b*(time+dt[i].c));
22         vis[i]=0;
23     }
24 }
25 int main(){
26     int T;
27     scanf("%d",&T);
28     while(T--){
29         scanf("%d%d",&n,&t);
30         for(int i=0;i<n;i++){
31             scanf("%d%d%d",&dt[i].a,&dt[i].b,&dt[i].c);
32         }
33         memset(vis,0,sizeof(vis));
34         ans=0;
35         dfs(0,0);
36         printf("%d\n",ans);
37     }
38     return 0;
39 }
时间: 2024-10-12 15:35:55

The Highest Mark(01背包)的相关文章

hdu3448 01背包+dfs

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3448 Description 0/1 bag problem should sound familiar to everybody. Every earth man knows it well. Here is a mutant: given the capacity of a bag, that is to say, the number of goods the bag can ca

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

Description 贝茜在珠宝店闲逛时,买到了一个中意的手镯.很自然地,她想从她收集的 N(1 <= N <= 3,402)块宝石中选出最好的那些镶在手镯上.对于第i块宝石,它的重量为W_i(1 <= W_i <= 400),并且贝茜知道它在镶上手镯后能为自己增加的魅力值D_i(1 <= D_i <= 100).由于贝茜只能忍受重量不超过M(1 <= M <= 12,880)的手镯,她可能无法把所有喜欢的宝石都镶上. 于是贝茜找到了你,告诉了你她所有宝石

hdu 3449 (有依赖的01背包)

依赖背包 事实上,这是一种树形DP,其特点是每个父节点都需要对它的各个儿子的属性进行一次DP以求得自己的相关属性. fj打算去买一些东西,在那之前,他需要一些盒子去装他打算要买的不同的物品.每一个盒子有特定要装的东西(就是说如果他要买这些东西里的一个,他不得不先买一个盒子).每一种物品都有自己的价值,现在FJ只有W元去购物,他打算用这些钱买价值最高的东西. Problem Description FJ is going to do some shopping, and before that,

uva--10163(dp,01背包,双肩包)

10163 Storage Keepers Randy Company has N (1  N  100) storages. Company wants some men to keep them safe. Now there are M (1  M  30) men asking for the job. Company will choose several from them. Randy Company employs men following these rules: 1

hdu 4044 GeoDefense (树形dp+01背包)

GeoDefense Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 663    Accepted Submission(s): 267 Problem Description Tower defense is a kind of real-time strategy computer games. The goal of towe

01背包,概率

原题http://acm.hdu.edu.cn/showproblem.php?pid=2955 Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 11820    Accepted Submission(s): 4398 Problem Description The aspiring Roy the Robber

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

17-又见01背包

/*                                        又见01背包时间限制:1000 ms  |  内存限制:65535 KB难度:3 描述        有n个重量和价值分别为wi 和 vi 的 物品,从这些物品中选择总重量不超过 W     的物品,求所有挑选方案中物品价值总和的最大值.    1 <= n <=100    1 <= wi <= 10^7    1 <= vi <= 100    1 <= W <= 10^

HDU - 2602 Bone Collector(01背包讲解)

题意:01背包:有N件物品和一个容量为V的背包.每种物品均只有一件.第i件物品的费用是volume[i],价值是value[i],求解将哪些物品装入背包可使价值总和最大. 分析: 1.构造二维数组:dp[i][j]---前i件物品放入一个容量为j的背包可以获得的最大价值. dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - volume[i]] + value[i]);---(a) (1)dp[i - 1][j]---不放第i件物品,因此前i件物品放入一个容量为