题目链接

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. centos无法通过ssh连接的解决

    系统环境是centos7,虚拟机环境下的.在使用ssh工具连接虚拟机的时候发现连接不上,用的是root 先检查openssh-server是否安装: yum list installed | grep ...

  2. [转载]function与感叹号

    http://swordair.com/function-and-exclamation-mark/ 最近有空可以让我静下心来看看各种代码,function与感叹号的频繁出现,让我回想起2个月前我回杭 ...

  3. mysql 允许远程登录

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;flush privileges;

  4. subtle:有趣的伪平铺式窗口管理器

    Author:吴吉庆 email: jiqingwu@gmail.com home:http://hi.baidu.com/jiqing0925 create:2011-02-19 update:20 ...

  5. 【leetcode 简单】 第八十一题 4的幂

    给定一个整数 (32 位有符号整数),请编写一个函数来判断它是否是 4 的幂次方. 示例 1: 输入: 16 输出: true 示例 2: 输入: 5 输出: false 进阶: 你能不使用循环或者递 ...

  6. 可能是最漂亮的Spring事务管理详解

    Java面试通关手册(Java学习指南):https://github.com/Snailclimb/Java_Guide 微信阅读地址链接:可能是最漂亮的Spring事务管理详解 事务概念回顾 什么 ...

  7. 【工具记录】Linux口令破解

    1.基础知识 /etc/passwd:记录着用户的基本属性,所有用户可读 字段含义如下: 用户名:口令:用户标识号:组标识号:注释性描述:主目录:登录Shell eg: root:x:0:0:root ...

  8. UBIFS文件系统简介 与 利用mkfs.ubifs和ubinize两个工具制作UBI镜像 (完整理解版本)

    UBI文件系统简介 在linux-2.6.27以前,谈到Flash文件系统,大家很多时候多会想到cramfs.jffs2.yaffs2等文件系统. 它们也都是基于文件系 统+mtd+flash设备的架 ...

  9. CSS锚伪类顺序需注意的几点

    CSS锚伪类有以下几种: a:link{color:pink} /*未访问的链接*/ a:visited{color:red} /*已访问的链接*/ a:hover{color:blue} /*鼠标移 ...

  10. WebApi参数问题方案

    原文:http://www.cnblogs.com/landeanfen/p/5337072.html