xdoj 1146 (逆向01背包)
背包 有:01背包 逆向背包 多重背包 完全背包 所有的背包都可以根据更新的方向一维实现
amazing?!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstring>
using namespace std;
const int N=5e4;
int dp[N+];
int n,W;
int main ()
{
while (~scanf ("%d %d",&n,&W)) {
memset (dp,0x3f,sizeof(dp));
dp[]=;
for (int i=;i<=n;i++) {
int cost,value;
scanf ("%d %d",&cost,&value);
for (int j=N;j>=value;j--)
dp[j]=min(dp[j],dp[j-value]+cost);
}
for (int i=N;i>=;i--)
if (dp[i]<=W) {
printf ("%d\n",i);
break;
}
}
return ;
}
xdoj 1146 (逆向01背包)的更多相关文章
- hdu 6092 Rikka with Subset(逆向01背包+思维)
Rikka with Subset Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- UVALive 4870 Roller Coaster --01背包
题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F , D -= K 问在D小于等于一定限度的时 ...
- POJ1112 Team Them Up![二分图染色 补图 01背包]
Team Them Up! Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7608 Accepted: 2041 S ...
- Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)
传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...
- 51nod1085(01背包)
题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1085 题意: 中文题诶~ 思路: 01背包模板题. 用dp[ ...
- *HDU3339 最短路+01背包
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- codeforces 742D Arpa's weak amphitheater and Mehrdad's valuable Hoses ——(01背包变形)
题意:给你若干个集合,每个集合内的物品要么选任意一个,要么所有都选,求最后在背包能容纳的范围下最大的价值. 分析:对于每个并查集,从上到下滚动维护即可,其实就是一个01背包= =. 代码如下: #in ...
- POJ 3624 Charm Bracelet(01背包)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34532 Accepted: 15301 ...
- (01背包变形) Cow Exhibition (poj 2184)
http://poj.org/problem?id=2184 Description "Fat and docile, big and dumb, they look so stupid ...
随机推荐
- Java连接Oracle/MySQL数据库教程
一.下载 oracle java驱动下载地址:http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090 ...
- 微信小程序 HMACSHA256 哈希加密
下载CryptoJS, 增加红色的这句 module.exports = CryptoJS /* CryptoJS code.google.com/p/crypto-js (c) 2009-2012 ...
- SpringBoot使用Spring Initializer
IDE都支持使用Spring的项目创建Spring的项目创建向导,快速创建一个SpringBoot项目:选择我们需要的模块:向导会联网创建SpringBoot项目:默认生成的SpringBoot项目: ...
- linux jdk install and tomcat install
1● linux安装jdk1.8 Download jdk1.8 export JAVA_HOME=/usr/java/jdk1.8.0_181 export JRE_HOME=${JAVA_ ...
- Best Paper Awards in Computer Science 链接
http://jeffhuang.com/best_paper_awards.html#icml
- shell脚本学习之参数传递
shell之参数传递 我们可以在执行 Shell 脚本时,向脚本传递参数,脚本内获取参数的格式为:$n.n 代表一个数字,1 为执行脚本的第一个参数,2 为执行脚本的第二个参数,以此类推…… 实例 以 ...
- linux的典型分支:
1.redhat 2.debian 3.centOS 4.ubuntu 5.fedora 6.kali linux
- java this的用法
this 含义:代表当前对象 用法: 用于返回对象的引用 示例代码 public class Test { public Test f() { return this;//获取当前对象的引用 } pu ...
- [转载]Java创建WebService服务及客户端实现
Java创建WebService服务及客户端实现 Java创建WebService服务及客户端实现
- L257 论述型作文模板
一引出相同观点: 1.With the development of science and technology, more and more people believe that...随着科技的 ...