题目链接

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. 64位Ubuntu 安装scrapy遇到的问题

    这两天准备开始学习Python爬虫,安装scrapy框架后出现 Traceback (most recent call last): File "/usr/local/bin/scrapy& ...

  2. 在升级Windows 8.1后,桌面的右下角显示"SecureBoot未正确配置"

    原地址为:http://ask.zol.com.cn/q/201881.html 第一种模式BIOS: 在将Secure Boot设置为Enabled后,Secure Boot Status依然为关闭 ...

  3. ICPC 2015 Shenyang Online-E-EXCITED DATAbase

    题目描述 She says that any Pavarotti among the nightingales will serenade his mate while she sits on her ...

  4. bzoj千题计划161:bzoj1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果

    http://www.lydsy.com/JudgeOnline/problem.php?id=1589 tarjan缩环后拓扑排序上DP #include<cstdio> #includ ...

  5. 【学习DIV+CSS】2. 学习CSS(一)--CSS控制页面样式

    1. CSS如何控制页面 使用XHTML+CSS布局页面,其中有一个很重要的特点就是“结构与表现相分离”(结构指XHTML,表现指CSS).有人这样描述这种分离的关系,结构XHTML好比一个人,表现C ...

  6. Python核心编程——Chapter9

    好久没写过Python了,前一阵子忙这忙那的,都几乎把Python给丢掉了,话不多说,马上开始. 9.1.文件过滤.显示一个文件的所有行,并且忽略以井号开头的行. 其实这个题目比较基础,用shell语 ...

  7. Java 图片转字节流 实现 图片->字节流(字符串)->图片

    //该方法实现图片转String 参数为图片的路径 可以是file.toString()得到public String testUpload(String path) { try { String s ...

  8. 20155233 2016-2017-2 《Java程序设计》第6周学习总结

    20155233 2016-2017-2 <Java程序设计>第6周学习总结 学习目标 理解流与IO 理解InputStream/OutPutStream的继承架构 理解Reader/Wr ...

  9. ASP.NET 应用生命周期19个事件简介

    下面是请求管道中的19个事件. (1)BeginRequest: 开始处理请求 (2)AuthenticateRequest授权验证请求,获取用户授权信息 (3):PostAuthenticateRe ...

  10. 钉钉头像大小设置 阿里cdn尺寸截取参数设置

    默认api的接口返回的avatar字段,是原始图片大小字段,尺寸和空间都是原始大小,如果想节省流量或统一尺寸,可以用阿里cdn自带的尺寸截取功能, 比如钉钉头像 avatar字段 返回值为原始大小ht ...