题目链接:http://poj.org/problem?id=3624

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 andDi

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

题解:还是01背包模板题
 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
return x>y;
}
const int N=;
const int mod=1e9+;
int dp[N];
int main()
{
std::ios::sync_with_stdio(false);
int n,m,x,y;
mem(dp);
cin>>n>>m;
for(int i=;i<=n;i++){
cin>>x>>y;
for(int j=m;j>=x;j--){
dp[j]=max(dp[j],dp[j-x]+y);
}
}
cout<<dp[m]<<endl;
return ;
}

POJ 3624 Charm Bracelet (01背包)的更多相关文章

  1. POJ 3624 Charm Bracelet(01背包裸题)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38909   Accepted: 16862 ...

  2. POJ 3624 Charm Bracelet(01背包)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34532   Accepted: 15301 ...

  3. POJ 3624 Charm Bracelet 0-1背包

    传送门:http://poj.org/problem?id=3624 题目大意:XXX去珠宝店,她需要N件首饰,能带的首饰总重量不超过M,要求不超过M的情况下,使首饰的魔力值(D)最大. 0-1背包入 ...

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

    题目链接 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 52318   Accepted: 21912 Descriptio ...

  5. poj 3624 Charm Bracelet 01背包问题

    题目链接:poj 3624 这是最基础的背包问题,特点是:每种物品仅有一件,可以选择放或不放.             用子问题定义状态:即F [i, v]表示前i件物品恰放入一个容量为v 的背包可以 ...

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

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

  7. POJ 3624 Charm Bracelet(0-1背包模板)

    http://poj.org/problem?id=3624 题意:给出物品的重量和价值,在重量一定的情况下价值尽可能的大. 思路:经典0-1背包.直接套用模板. #include<iostre ...

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

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

  9. poj 3624 Charm Bracelet(01背包)

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

随机推荐

  1. C++中的内存区域及其性能特征

    首先须要指出的是.我们通经常使用"堆"和"自由存储"这两个术语来区分两种不同类型的动态分配内存. 1.常量数据:常量数据区域主要用于存储字符串以及其它在编译期就 ...

  2. 20181223 Oracle中while

    最近尝试了一次while跑数, declare sysdataend  date:=system-1; startdata  date:=to_date('20181214','YYYYMMDD'); ...

  3. Redis入门到高可用(十)—— Spring与Redis的整合

    1.pom文件 <!--redis--> <dependency> <groupId>org.springframework.data</groupId> ...

  4. react img 被自动转成base64,无法根据当前路径来动态改变值的解决办法

    项目需求,需要根据当前的图片的路径值的来(加或者减)动态改变其值: state定义如下: this.state={ basket01:0+require("../../img/egg/egg ...

  5. 【设计模式】用追MM来解释23种设计模式,转

    创建型模式 1.FACTORY—追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯德基,只管向服务员说“来四个鸡翅”就行了.麦当劳和肯德基 ...

  6. 10.26 配置psplkf小程序

    环境 服务器 Win Server 2008,nginx, maven, psplkf 标准的mvn工程,可以使用eclipse,导入,file-import-maven project就行, 但是我 ...

  7. 远程访问对象java实现

    服务端: 定义远程接口: package com.my.rmi; import java.rmi.Remote; import java.rmi.RemoteException; public int ...

  8. 采用Extjs MVVM + ThinkPHP 架构开发的思考

    前后台号称都是MVC模式, 后台ThinkPHP框架实际上只提供web操作接口,直接返回json数据,因此只能算有Model和Controller两层, 前台ExtjsMVVM模式实际上就是分模块后的 ...

  9. cocos2d-x JS 获取屏幕大小或中点

    以一张背景图为例: var HelloWorldLayer = cc.Layer.extend({ ctor:function () { this._super(); var bg = new cc. ...

  10. Error #2148

    参考:https://blog.csdn.net/watersevenmmfx/article/details/52980804 chrome flash 安全沙箱冲突 SecurityError: ...