题目链接

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. ASP.NET IOC之 AutoFac的认识和结合MVC的使用

    这几天研究了解发现AutoFac是个牛X的IOC容器,是.NET领域比较流行的IOC框架之一,传说是速度最快的,~ 据相关资料,相关学习,和认知,遂做了一些整理 优点: 它是C#语言联系很紧密,也就是 ...

  2. Spring boot 集成 mybaits plus(代码生成器)

    源码地址:https://github.com/YANGKANG01/Spring-Boot-Demo 代码生成操作 在pom.xml文件中引入以下包: <!-- mybatisplus与spr ...

  3. 判断android是否是debug

    1.使用BuildConfig.DEBUG,这个在住modul里面是有效的,但是在有依赖库里面使用就会一直返回false,可以通过下面的方法解决:在library的build.gradle中添加以下代 ...

  4. Centos7系统中安装Nginx1.8.0

    Nginx的安装 tar -zxvf nginx-1.8.0.tar.gz cd nginx-1.8.0 ./configure make make install /usr/local/nginx/ ...

  5. [转]天才计算机程序员 -- fabrice bellard

    这位老兄就是用javascript写linux的那位,他的主页是:http://bellard.org/ 上面有他的几个作品,包括qemu,ffmpeg,tcc等. 这个世界从来不缺天才,只缺乏利用天 ...

  6. LintCode 412: Candy

    LintCode 412: Candy 题目描述 有 N 个小孩站成一列.每个小孩有一个评级. 按照以下要求,给小孩分糖果: 每个小孩至少得到一颗糖果. 评级越高的小孩可以得到更多的糖果. 需最少准备 ...

  7. SearchSploit

    在我们的GitHub上的Exploit Database存储库中包含一个名为"searchsploit"的Exploit-DB的命令行搜索工具,该工具还允许您在任何地方随身携带一个 ...

  8. Entity Framework(EF的Model First方法)

    EntityFramework,是Microsoft的一款ORM(Object-Relation-Mapping)框架.同其它ORM(如,NHibernate,Hibernate)一样, 一是为了使开 ...

  9. Fetch API 了解 及对比ajax、axois

    Fetch是什么 Fetch 是一个现代的概念, 等同于 XMLHttpRequest.它提供了许多与XMLHttpRequest相同的功能,但被设计成更具可扩展性和高效性.Fetch被很多浏览器所支 ...

  10. 阿里云CentOS下安装jdk

    首先需要下载jdk: 由于oracle上的下载页面有跳转,直接用wget下载下来的只是html页面.可以用下面的命令: wget --no-cookies --no-check-certificate ...