先排序预处理,后01背包。

 #include <stdio.h>
#include <string.h>
#include <stdlib.h> #define MAX(a, b) (a>b) ? a:b int dp[]; typedef struct {
int p, q, v;
} stuff_st; stuff_st stuffs[]; int comp(const void *a, const void *b) {
stuff_st *p = (stuff_st *)a;
stuff_st *q = (stuff_st *)b; return (p->q-p->p) - (q->q-q->p);
} int main() {
int n, m;
int i, j; while (scanf("%d %d", &n, &m) != EOF) {
for (i=; i<=n; ++i) {
scanf("%d%d%d", &stuffs[i].p, &stuffs[i].q, &stuffs[i].v);
}
memset(dp, , sizeof(dp));
qsort(stuffs+, n, sizeof(stuff_st), comp);
for (i=; i<=n; ++i) {
for (j=m; j>=stuffs[i].q; --j) {
dp[j] = MAX(dp[j], dp[j-stuffs[i].p]+stuffs[i].v);
}
/*
for (j=0; j<=m; ++j) {
printf("%d ", dp[j]);
}
printf("\n");
*/
}
printf("%d\n", dp[m]);
} return ;
}

【HDOJ】3466 Proud Merchants的更多相关文章

  1. HDU 3466 Proud Merchants 带有限制的01背包问题

    HDU 3466 Proud Merchants 带有限制的01背包问题 题意 最近,伊萨去了一个古老的国家.在这么长的时间里,它是世界上最富有.最强大的王国.因此,即使他们的国家不再那么富有,这个国 ...

  2. HDU 3466 Proud Merchants【贪心 + 01背包】

    Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...

  3. HDU 3466 Proud Merchants(01背包问题)

    题目链接: 传送门 Proud Merchants Time Limit: 1000MS     Memory Limit: 65536K Description Recently, iSea wen ...

  4. HDU 3466 Proud Merchants(01背包)

    这道题目看出背包非常easy.主要是处理背包的时候须要依照q-p排序然后进行背包. 这样保证了尽量多的利用空间. Proud Merchants Time Limit: 2000/1000 MS (J ...

  5. hdu 3466 Proud Merchants 01背包变形

    Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) ...

  6. HDU 3466 Proud Merchants(01背包)

    题目链接: 传送门 Proud Merchants Time Limit: 1000MS     Memory Limit: 65536K Description Recently, iSea wen ...

  7. hdu 3466 Proud Merchants(有排序的01背包)

    Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) ...

  8. hdu 3466 Proud Merchants 【限制性01背包】+【贪心】

    题目链接:https://vjudge.net/contest/103424#problem/J 转载于:https://www.bbsmax.com/A/RnJW16GRdq/ 题目大意: 有n个商 ...

  9. HDOJ 3466 Proud Merchants

    Problem Description Recently, iSea went to an ancient country. For such a long time, it was the most ...

随机推荐

  1. Bye 14 Hello 15

         打开博客.空间 窥探到大家都在写自己的2014,抬头一看日历2015已近在咫尺了,看着别人的成长(例如 今年看了多少书.做了什么项目.工资涨了多少.职位角色的变化.去了多少地方.还有一些发善 ...

  2. Sql2008的行列转换之行转列

    今天在工作的时候遇到了行列转换的问题,记得去年有一段时间经常写,但是许久不用已经记不太得了.好记性不如烂笔头,忙完之后赶紧记录一下. 关键字:PIVOT(行转列),UNPIVOT(列转行) 先说说 P ...

  3. DOS 全集

       DOS全集 winver 检查Windows版本 wmimgmt.msc 打开Windows管理体系结构(wmi) wupdmgr Windows更新程序 wscript Windows脚本宿主 ...

  4. SQL 编译与重编译

    编译的含义 当SQLSERVER收到任何一个指令,包括查询(query).批处理(batch).存储过程.触发器(trigger) .预编译指令(prepared statement)和动态SQL语句 ...

  5. objective-c ios webkit 本地存储local-storage

    我有一个Cocoa / Objective-C的应用程序,它嵌入了一个WebKit的web视图.我需要打开的数据库支持和本地存储.我知道这是可以做到-我有它在Safari中工作-但我无法找到如何设置这 ...

  6. Win7下Boost库的安装

    Boost库是C++领域公认的经过千锤百炼的知名C++类库,涉及编程中的方方面面,简单记录一下使用时的安装过程 1.boost库的下载 boost库官网主页:www.boost.org 2.安装 将下 ...

  7. MySQL分库分表备份脚本

    MySQL分库备份脚本 #脚本详细内容 [root@db02 scripts]# cat /server/scripts/Store_backup.sh #!/bin/sh MYUSER=root M ...

  8. ubuntu nginx 伪静态 设置

    简单的静态设置 1  vim nginx.conf // 修改nginx配置文件 server { .... root /usr/local/nginx/html; #nginx网站根目录 #下面这个 ...

  9. 【实习记】2014-09-01从复杂到简单:一行命令区间查重+长整型在awk中的bug

        9月1号,导出sql文件后,想到了awk,但很复杂.想到了用sed前期处理+python排序比较的区间查重法.编写加调试用了约3小时. 9月2号,编写C代码的sql语句过程中,发现排序可以交m ...

  10. centos 6.5 安装jenkins

    Installation sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.rep ...