if(j>=w[i])

dp[i][j] = max(dp[i-1][j-w[i]]+v[i], dp[i-1][j]);

else
dp[i][j]=dp[i-1][j];
i
1
2
3
4
5
w
1
2
3
4
5
v
5
4
3
2
1
 

i代表前i件物品,j代表背包容量;

 
 
i\dp\j
0 0 0 0
0
0
0
0
0
0
0
0
5 5 5
5
5
5
5
5
5
5
0
5
5
9
9
9
9
9
9
9
9
0
5
5
9
9
9
12
12
12
12
12
0
5
5
9
9
9
12
12
12
12
14
0
5
5
9
9
9
12
12
12
12
14
 
/*

1 0

2 0


*/
 
 
 
 
动态规划求dp【5】【10】;
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define N 1010 using namespace std; int w[N],v[N],dp[N][N]; int main()
{
int i,j,T,WW,VV; cin>>T; while(T--)
{
memset(dp,,sizeof(dp));
cin>>WW>>VV; for(i=;i<=WW;i++)
cin>>v[i];
for(i=;i<=WW;i++)
cin>>w[i];
for(i=;i<=WW;i++)
{
for(j=;j<=VV;j++)//j=0//当当背包的承受量和商品的重量都为0时,价值都应加上;如果j=1时;不能加上价值;
            {
if(j>=w[i])
dp[i][j]=max(dp[i-][j],dp[i-][j-w[i]]+v[i]);
else
dp[i][j]=dp[i-][j];
}
}
printf("%d\n",dp[WW][VV]); }
return ; }

Bone Collector的更多相关文章

  1. hdu 2602 Bone Collector(01背包)模板

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...

  2. HDU 2602 Bone Collector WA谁来帮忙找找错

    Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...

  3. Bone Collector(01背包)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N 题目: Description Many year ...

  4. HDU 3639 Bone Collector II(01背包第K优解)

    Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  5. Bone Collector II

    Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...

  6. HDU 2602 Bone Collector (简单01背包)

    Bone Collector http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , i ...

  7. hdu 2602 Bone Collector 背包入门题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 题目分析:0-1背包  注意dp数组的清空, 二维转化为一维后的公式变化 /*Bone Coll ...

  8. hdu 2639 Bone Collector II

    Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  9. 杭电 2602 Bone Collector

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  10. HDU 2602 Bone Collector

    http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...

随机推荐

  1. TYVJ P1031 热浪 Label:dijkstra 最短路

    背景 USACO OCT09 9TH 描述 德克萨斯纯朴的民眾们这个夏天正在遭受巨大的热浪!!!他们的德克萨斯长角牛吃起来不错,可是他们并不是很擅长生產富含奶油的乳製品.Farmer John此时以先 ...

  2. HDU 4681 String(DP)

    题目链接 枚举A和B中每一段含有C的段,A的前面 后面和B前面后面,求最长公共子序.观察发现,可以预处理最长公共子序. #include <iostream> #include <c ...

  3. POJ 2112 Optimal Milking(最大流+二分)

    题目链接 测试dinic模版,不知道这个模版到底对不对,那个题用这份dinic就是过不了.加上优化就WA,不加优化TLE. #include <cstdio> #include <s ...

  4. Git补丁

    引子: 上班有问题没有解决,在家里搞定了,于是把改动打成一个补丁,明天应用到公司的工作电脑上.(以下内容转自别处) 1.创建补丁,比如把最新的两次提交纪录转化为补丁文件,可以用如下命令: git fo ...

  5. Html - SPA页面收集(有图)

    场景,左图,又字段的布局 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

  6. 分布式架构高可用架构篇_04_Keepalived+Nginx实现高可用Web负载均衡

    参考: 龙果学院http://www.roncoo.com/share.html?hamc=hLPG8QsaaWVOl2Z76wpJHp3JBbZZF%2Bywm5vEfPp9LbLkAjAnB%2B ...

  7. portable runtime

    APR The mission of the Apache Portable Runtime (APR) project is to create and maintain software libr ...

  8. c/c++内存调试

    Leaktracer,Valgrind,ElectricFence 内存泄漏分类 以发生的方式来分类,内存泄漏可以分为4类: 常发性 发生内存泄漏的代码会被多次执行到,每次被执行的时候都会导致一块内存 ...

  9. 2016.03.31,英语,《Vocabulary Builder》Unit 08

    tend/tent: from the Latin tendere, meaning 'to stretch, extend, or spread'. tent: [tent] n. 帐篷 vt.&a ...

  10. Javascript 笔记与总结(2-17)事件委托

    [例]五子棋,单次点击为黑色,偶次点击为白色.e.target 的用法 <!DOCTYPE html> <html lang="en"> <head& ...