题意:买东西,每个东西有三个特征值,p代表价格,q代表你手中钱必须不低于q才能买这个物品,v代表得到的价值。

mark:又是变种01背包,每做一个变种的,就是一种提高。。

按照q - p以由大到小的顺序排序,然后进行01背包的DP即可。

#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
const int MAXN=5005;
int dp[MAXN];
struct Node
{
int p,q,v;
}node[505];
bool cmp(Node a,Node b)
{
return (a.q-a.p)<(b.q-b.p);
}
int main()
{
int n,m;
int i,j;
int p,q,v;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=0;i<=m;i++)
dp[i]=0;
for(i=0;i<n;i++)
{
scanf("%d%d%d",&node[i].p,&node[i].q,&node[i].v);
}
sort(node,node+n,cmp);
for(i=0;i<n;i++)
{
for(j=m;j>=node[i].p;j--)
{
if(j>=node[i].q)
dp[j]=max(dp[j],dp[j-node[i].p]+node[i].v);
}
}
int ans=0;
for(i=1;i<=m;i++)
if(ans<dp[i]) ans=dp[i];
printf("%d\n",ans); }
return 0;
}

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

  1. POJ3211 Washing Clothes[DP 分解 01背包可行性]

    Washing Clothes Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 9707   Accepted: 3114 ...

  2. [HDOJ5543]Pick The Sticks(DP,01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意:往长为L的线段上覆盖线段,要求:要么这些线段都在L的线段上,要么有不超过自身长度一半的部分 ...

  3. poj 2184 Cow Exhibition(dp之01背包变形)

    Description "Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - ...

  4. hdu1203 I NEED A OFFER!---概率DP(01背包)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1203 题目大意:Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材 ...

  5. HDU 2955 Robberies(概率DP,01背包)题解

    题意:给出规定的最高被抓概率m,银行数量n,然后给出每个银行被抓概率和钱,问你不超过m最多能拿多少钱 思路:一道好像能直接01背包的题,但是有些不同.按照以往的逻辑,dp[i]都是代表i代价能拿的最高 ...

  6. DP入门——01背包 & 完全背包

    01背包: 采药: https://www.luogu.org/problemnew/show/P1048 #include <iostream> #include <algorit ...

  7. Codeforces Round #383 (Div. 2) D. Arpa's weak amphitheater and Mehrdad's valuable Hoses —— DP(01背包)

    题目链接:http://codeforces.com/contest/742/problem/D D. Arpa's weak amphitheater and Mehrdad's valuable ...

  8. CSU 1547 Rectangle(dp、01背包)

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1547 Description Now ,there are some rectang ...

  9. Temple Build~dp(01背包的变形)

    The Dwarves of Middle Earth are renowned for their delving and smithy ability, but they are also mas ...

随机推荐

  1. C# 动态装载 DLL

    C# 动态装载 DLL LoadDllTool.cs 如下: using System; using System.Collections.Generic; using System.Text; us ...

  2. 【Python】Python Mako模板使用

    参考资料: Mako Templates for Python官网:http://www.makotemplates.org/ Python模板库Mako的用法:http://my.oschina.n ...

  3. [转发] git设置代理

    一. 写的很好推荐,(http与ssh设置都有) https://imciel.com/2016/06/28/git-proxy/ 二. 只有 http的方式代码设置 http://stackover ...

  4. 在 WF 4 中编写自定义控制流活动

    在 WF 4 中编写自定义控制流活动 Leon Welicki 控制流是指组织和执行程序中各个指令的方法. 在 Windows Workflow Foundation 4 (WF 4) 中,控制流活动 ...

  5. Qt 之 QtConcurrent

    本文以 Qt 中的 QtConcurrent::run() 函数为例,介绍如何将函数运行在单独的某一个线程中. 1  QtConcurrent::run() QtConcurrent 是一个命名空间, ...

  6. 嵌入式 如何定位死循环或高CPU使用率(linux)

    如何定位死循环或高CPU使用率(linux)  确定是CPU过高 使用top观察是否存在CPU使用率过高现象 找出线程 对CPU使用率过高的进程的所有线程进行排序 ps H -e -o pid,tid ...

  7. 利用JqGrid结合ashx显示列表之一

    最近项目决定运用JqGrid列表控件显示相关数据,以前接触比较多还是easyui和Ext.Net的列表控件,文章简单写的小实例进行一个总结: 1:引入相关的JS及CSS文件,JqGrid目前可以利用J ...

  8. libsvm处理多分类的问题

    SVM是一个二分类器,当遇到多类别的时候,一般采取如下两种策略. a.一对多法(one-versus-rest,简称1-v-r SVMs).训练时依次把某个类别的样本归为一类,其他剩余的样本归为另一类 ...

  9. iOS动画进阶 - 实现炫酷的上拉刷新动效

    移动端訪问不佳,请訪问我的个人博客 近期撸了一个上拉刷新的小轮子.仅仅要遵循一个协议就能自己定义自己动效的上拉刷新和载入,我自己也写了几个动效进去,以下是一个比較好的动效的实现过程 先上效果图和git ...

  10. oracle修改用户密码过期时间

    Oracle默认在default概要文件中设置了“PASSWORD_LIFE_TIME=180天”,导致密码过期,程序无法使用,业务进程会提示无法连接数据库等字样. --查询默认密码过期时间 SELE ...