题目链接

http://poj.org/problem?id=3624

题意

有n个手镯,每个手镯有两个属性:重量W,需求因子D。还有一个背包,它能装下总重量不超过M的手镯。现在将一些镯子装入背包,求所装入镯子总需求因子的最大值。

思路

01背包问题,使用动态规划解决。

代码

 #include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std; const int N = ;
const int M = ;
int dp[M];
int w[N], d[N]; int main()
{
//freopen("hdoj3624.txt", "r", stdin);
int n, m;
while (cin >> n >> m)
{
for (int i = ; i <= n; i++)
cin >> w[i] >> d[i]; for (int i = ; i <= n; i++)
{
for (int j = m; j >= ; j--) //j是逆序
{
if (w[i] <= j)
dp[j] = max(dp[j - w[i]] + d[i], dp[j]);
}
}
cout << dp[m] << endl;
}
return ;
}

poj3624 Charm Bracelet(DP,01背包)的更多相关文章

  1. POJ.3624 Charm Bracelet(DP 01背包)

    POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...

  2. POJ3624 Charm Bracelet 【01背包】

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22621   Accepted: 10157 ...

  3. Poj3624 Charm Bracelet (01背包)

    题目链接:http://poj.org/problem?id=3624 Description Bessie has gone to the mall's jewelry store and spie ...

  4. poj 3524 Charm Bracelet(01背包)

    Description Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd ...

  5. POJ 3624 Charm Bracelet (01背包)

    题目链接:http://poj.org/problem?id=3624 Bessie has gone to the mall's jewelry store and spies a charm br ...

  6. POJ 3624 Charm Bracelet(01背包模板)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 45191   Accepted: 19318 ...

  7. Charm Bracelet(01背包)

    Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fil ...

  8. poj 3624 Charm Bracelet(01背包)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29295   Accepted: 13143 ...

  9. P2871 [USACO07DEC]手链Charm Bracelet(01背包模板)

    题目传送门:P2871 [USACO07DEC]手链Charm Bracelet 题目描述 Bessie has gone to the mall's jewelry store and spies ...

  10. [转]POJ3624 Charm Bracelet(典型01背包问题)

    来源:https://www.cnblogs.com/jinglecjy/p/5674796.html 题目链接:http://bailian.openjudge.cn/practice/4131/ ...

随机推荐

  1. CSS3实战之box-sizing

    一般我们都认为border和padding都包含在width或height之内. 而现代标准的浏览器一般都认为width和height仅仅包含content,刨去了border和padding区域. ...

  2. php检测文件编码方法[非完美]

    关于文件编码的检测,百度一下一大把都是,但是确实没有能用的. 很多人建议 mb_detect_encoding 检测,可是不知为何我这不成功,什么都没输出. 看到有人写了个增强版,用 BOM 判断的, ...

  3. 【HDU】2191 多重背包问题

    原题目:悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 [算法]多重背包(有限背包) 动态规划 [题解]http://blog.csdn.net/acdreamers/article/detail ...

  4. 面向对象__construct(构造方法)、__destruct(析构方法)

    //1.创建子类的时候构造函数会直接取创建函数时传的参数,例如下面例子中构造函数直接取了new Person("张三","男", 20);里面的3个参数. // ...

  5. 微服务深入浅出(5)-- 声明式调用Feign

    Feign的使用 Feign采用了声明式的API接口的风格,将Java Http客户端绑定到它的内部,从而调用过程变的简单. 配置文件: spring: application: name: eure ...

  6. HDU 1994 利息计算 数学题

    解题报告:算利息的,不过一开始格式控制符里面少写了一个%lf,一直没看到,愣是没找到错误,唉! #include<cstdio> int main() { int T; scanf(&qu ...

  7. httpd.conf详解,因为php始终报fileinfo扩展无法加载的错

    # # This is the main Apache HTTP server configuration file. It contains the # configuration directiv ...

  8. css给表格每一列设置不同的样式

    第一列#id table tr td:first-child{ overflow: visible; }第二列table tr td:first-child+td{color:#666;}第三列tab ...

  9. CentOS时区GMT修改为CST

    GMT:格林尼标准时间 北京时间=GMT时间+8小时 [root@sa~]# date -R 查看目前服务器的时间标准 [root@sa~]# vi /etc/sysconfig/clock 将ZON ...

  10. C#抓取网络图片保存到本地

    C#抓取网络图片保存到本地 System.Net.WebClient myWebClient = new System.Net.WebClient(); //将头像保存到服务器 string virP ...