D - Charm Bracelet 背包问题
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the supplied list has a weight Wi (1 ≤ Wi ≤ 400), a 'desirability' factor Di (1 ≤ Di ≤ 100), and can be used at most once. Bessie can only support a charm bracelet whose weight is no more than M (1 ≤ M ≤ 12,880).
Given that weight limit as a constraint and a list of the charms with their weights and desirability rating, deduce the maximum possible sum of ratings.
Input
* Line 1: Two space-separated integers: N and M
* Lines 2..N+1: Line i+1 describes charm i with two space-separated integers: Wi and Di
Output
* Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints
Sample Input
4 6
1 4
2 6
3 12
2 7
Sample Output
23
Home Problems Status Contest [xiong_tao] Logout
xiong_tao 's source code for D
Memory: KB Time: MS
Language: G++ Result: Accepted #include<cstdio>
#include<string.h>
using namespace std;
int dp[],w[],d[];
int n,m;
int main()
{
int i,j;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=;i<n;i++)
scanf("%d%d",&w[i],&d[i]);
memset(dp,,sizeof(dp));
for(i=;i<n;i++)
for(j=m;j>=;j--)
if(j>=w[i])
dp[j]=dp[j]>dp[j-w[i]]+d[i]?dp[j]:dp[j-w[i]]+d[i];
printf("%d\n",dp[m]);
}
return ;
} FAQ | About Virtual Judge | Forum | Discuss | Open Source Project
All Copyright Reserved ©- HUST ACM/ICPC TEAM
Anything about the OJ, please ask in the forum, or contact author:Isun
Server Time: -- ::
D - Charm Bracelet 背包问题的更多相关文章
- POJ 3624 Charm Bracelet 背包问题的解决方案
最简单的背包问题,标题应该是除了背包测试中心:您无法打开二维数组.我还没有开的二维.光看数据是不可能的. 太大. 有两种方法来提高全省内存DP: 1 所谓卷的阵列 2 反向表 久没做背包DP,突然认为 ...
- 01背包问题:Charm Bracelet (POJ 3624)(外加一个常数的优化)
Charm Bracelet POJ 3624 就是一道典型的01背包问题: #include<iostream> #include<stdio.h> #include& ...
- [转]POJ3624 Charm Bracelet(典型01背包问题)
来源:https://www.cnblogs.com/jinglecjy/p/5674796.html 题目链接:http://bailian.openjudge.cn/practice/4131/ ...
- Charm Bracelet(01背包问题)
题目链接: https://vjudge.net/problem/POJ-3624 题目描述: Bessie has gone to the mall's jewelry store and spie ...
- POJ 3624 Charm Bracelet(01背包模板)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45191 Accepted: 19318 ...
- POJ 3624 Charm Bracelet(01背包)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34532 Accepted: 15301 ...
- Charm Bracelet
Charm Bracelet Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- poj 3524 Charm Bracelet(01背包)
Description Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd ...
- POJ 3624 Charm Bracelet(01背包裸题)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 38909 Accepted: 16862 ...
随机推荐
- c#中的反射
System.Reflection.AssemblySystem.Activator Assembly assembly = Assembly.load("namespace名") ...
- NSArray和NSDictionary的混合
- static方法,属性,代码块初始化顺序和执行顺序
http://greateryang.blog.163.com/blog/static/81953375201232621031508/
- 枚举IoTimer
/*************************************************************************************** * AUTHOR : ...
- HDU 4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)
题意:给定n*m个格子,每个格子能填0-k 的整数.然后给出每列之和和每行之和,问有没有解,有的话是不是唯一解,是唯一解输出方案. 思路:网络流,一共 n+m+2个点 源点 到行连流量为 所给的 ...
- Windows下将程序打包为安装包(最为简易的方式)
一.准备工作:先下载一个Inno Setup编译器,这里我用到的是5.3.3中文版的. 软件介绍: Inno Setup 是一个免费的安装制作软件,小巧.简便.精美是其最大特点,支持pascal脚本, ...
- NodeJs编写小爬虫
一,爬虫及Robots协议 爬虫,是一种自动获取网页内容的程序.是搜索引擎的重要组成部分,因此搜索引擎优化很大程度上就是针对爬虫而做出的优化. robots.txt是一个文本文件,robots是一个协 ...
- limit 百万级数据分页优化方法
mysql教程 这个数据库教程绝对是适合dba级的高手去玩的,一般做一点1万 篇新闻的小型系统怎么写都可以,用xx框架可以实现快速开发.可是数据量到了10万,百万至千万,他的性能还能那么高吗? 一点小 ...
- Linux-C程序的存储空间布局
正文段 指的是由CPU执行的机器代码,通常,正文段是可以共享的,执行的程序在存储器中只有一个副本.通常也是只读的,防止程序本身被修改. 初始化数据段 数据段,被明确赋值的变量,比如全局变量 非初始化数 ...
- C# 数据流操作 Stream 相关
FileStream:對文件執行讀取與寫入 MemoryStream:對內存進行讀取與寫入 BufferedStream:對緩沖器進行讀取與寫入 StreamReader/StreamWriter 命 ...