题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5501

二维数组:

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
#define N 3100
int dp[N][N];
struct node
{
int A, B, C;
}a[N]; int cmp(node p, node q)
{
return p.C*q.B < p.B*q.C;
}
int main()
{
int T, n, t;
scanf("%d", &T);
while(T--)
{
memset(a, , sizeof(a));
memset(dp, , sizeof(dp));
scanf("%d%d", &n, &t);
for(int i=; i<n; i++)
{
scanf("%d%d%d", &a[i].A, &a[i].B, &a[i].C);
}
sort(a, a+n, cmp);
int ans = ;
for(int i=; i<n; i++)
{
for(int j=; j<=t; j++)
{
if(j<a[i].C)
dp[i+][j] = dp[i][j];
else
dp[i+][j] = max(dp[i][j], dp[i][j-a[i].C]+a[i].A-j*a[i].B);
ans=max(dp[i+][j],ans);
}
}
printf("%d\n", ans);
}
return ;
}

一维数组:

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
#define N 3100
int dp[N];
struct node
{
int A, B, C;
}a[N]; int cmp(node p, node q)
{
return p.C*q.B < p.B*q.C;
}
int main()
{
int T, n, t;
scanf("%d", &T);
while(T--)
{
memset(a, , sizeof(a));
memset(dp, , sizeof(dp));
scanf("%d%d", &n, &t);
for(int i=; i<n; i++)
{
scanf("%d%d%d", &a[i].A, &a[i].B, &a[i].C);
}
sort(a, a+n, cmp);
int ans = ;
for(int i=; i<n; i++)
{
for(int j=t; j>=a[i].C; j--)
{
dp[j] = max(dp[j], dp[j-a[i].C]+a[i].A-j*a[i].B);
ans = max(ans, dp[j]);
} }
printf("%d\n", ans);
}
return ;
}

The Highest Mark---hdu5501(问题转化 01背包)的更多相关文章

  1. hdu1203--D - I NEED A OFFER!(转化01背包)

    D - I NEED A OFFER! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  2. hdu 2955(概率转化,01背包)

    Hot~~招聘——巴卡斯(杭州),壹晨仟阳(杭州),英雄互娱(杭州) (包括2016级新生)除了校赛,还有什么途径可以申请加入ACM校队? Robberies Time Limit: 2000/100 ...

  3. dp之01背包hdu3466(带限制的,当你所拥有的钱数大于某个限定值时才可以购买该物品)

    题意:买东西,每个东西有三个特征值,p代表价格,q代表你手中钱必须不低于q才能买这个物品,v代表得到的价值. mark:又是变种01背包,每做一个变种的,就是一种提高.. 按照q - p以由大到小的顺 ...

  4. HDU 5501:The Highest Mark 01背包

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

  5. The Highest Mark(01背包)

    The Highest Mark Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

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

  7. HDU5501/BestCoder Round #59 (div.2)The Highest Mark dp+贪心

    The Highest Mark 问题描述 2045年的SD省队选拔,赛制和三十年前已是完全不同.一场比赛的比赛时间有 tt 分钟,有 nn 道题目. 第 ii 道题目的初始分值为 A_i(A_i \ ...

  8. hdu5501 The Highest Mark

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

  9. HDU 5501 The Highest Mark

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

随机推荐

  1. easyui添加删除tooltip

    /** * 扩展两个方法 */$.extend($.fn.datagrid.methods, { /** * 开打提示功能 * @param {} jq * @param {} params 提示消息 ...

  2. js实现EasyUI-datagrid前台分页

    //实现假分页 function myLoader(param, success, error) { var that = $(this); var opts = that.datagrid(&quo ...

  3. C++ 引用本质的详解

    //引用本质的理解① #include<iostream> using namespace std; int GetA(){ ; return a; } int & GetB(){ ...

  4. 织梦dede模板中广告的去除方法?

    织梦)dede模板中广告的去除方法1.我们先删除头部的广告,找到templetsdefault下的head.htm文件,打开后找到<div>{dede:myad name=’innerTo ...

  5. Classification / Recognition

    转载 https://handong1587.github.io/deep_learning/2015/10/09/recognition.html#facenet Classification / ...

  6. 关于spring中注解和xml混合使用

    可以混合用.文档有说明: Spring can accommodate both styles and even mix them together. 混合用的话,有个先后顺序,xml配置会覆盖ann ...

  7. WinDbg 解决Font.ToLogFont AccessViolationExcetion

    有个程序总是在windows 2003 server 异常退出. 并且,  查看调用栈也肯奇怪, 应该是很正常的调用. 怀疑是堆溢出. 开启heap trace : C:\Program Files\ ...

  8. bootstrap基础学习三篇

    bootstrap的排版 1.标题 Bootstrap 中定义了所有的 HTML 标题(h1 到 h6)的样式 2.代码如下: <div class="container"& ...

  9. 表空间_暂时表空间引起的错误:ora-01652 小例

    原创作品,出自 "深蓝的blog" 博客,深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/46888243 报暂 ...

  10. 解决ScrollView滑动RecyclerView的卡顿

    我们不的不了解ViewConfiguration这个类,官方是这么解释的Contains methods to standard constants used in the UI for timeou ...