题目链接: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. centos 关闭selinux

    将SELINUX配置文件设置为 disabled 模式,禁用SELinux vim /etc/selinux/config SELINUX=disabled 然后reboot重启生效 setenfor ...

  2. ROS开发与常用命令

    初始化ROS的catkin工作空间:catkin_init_workspace 编译ROS的catkin工作空间:catkin_make 读取当前catkin工作空间的环境变量:source deve ...

  3. php5.6+Redis+Windows7安装 (phpstudy)

    Windows下为PHP安装redis扩展 1.使用phpinfo()函数查看PHP的版本信息,这会决定扩展文件版本. 2.下载php_igbinary-2.0.1-7.0-ts-vc14-x64.z ...

  4. 浪潮IOT知识点

    1 新增身份定义 以及 身份定义的属性表 要注意增加路由 2     '@trident/core'; 飘红,解决办法 import { TableSearchComponent } from '@t ...

  5. 一文看懂POS收单中"MCC"是什么意思?

    MCC的前世今生! 是否经常听人提起过“MCC”?听起来如此高大上的词,背后有着怎样的知识内涵呢?您知道吗?今天,我们就一起来了解了解“MCC”的前世今生,让它也“接接地气”吧!商户类别码(简称MCC ...

  6. 2019.04.09 电商24 订单模快 ORM

    前面三个模块已近结束,现在看是订单模块的.想一下淘宝上的订单,在购物车中选中,提交,跳转到订单界面. 获取传过来的信息,那也要建立一个订单表,当我支付的时候,也要获取一些数据,将这些数据放到这个表中 ...

  7. Spring MVC 简介及入门小例子

    说明:文章内容全部截选自实验楼教程[Spring MVC 简易教程] 一.什么是 Spring MVC Spring MVC 属于 SpringFrameWork 的后续产品,已经融合在 Spring ...

  8. async await的用法

    const fs = require('fs'); const readFile = function (fileName) { return new Promise(function (resolv ...

  9. js多个异步请求,按顺序执行next

    在js里面,偶尔会遇见需要多个异步按照顺序执行请求,又不想多层嵌套,,这里和promise.all的区别在于,promise或者Jquery里面的$.when 是同时发送多个请求,一起返回,发出去的顺 ...

  10. leetcode 108

    二分法建立二叉树,每次把左半部分作为左子树右半部分作为右子树,递归建立BST. #include<bits/stdc++.h> using namespace std; /** * Def ...