题意:有n件手镯,总重量不能超过M,每个手镯有一个体重W【i】和魅力V【i】,问在不超过M的情况下能获得的魅力总和

思路:把M当背包总容量,用0-1背包写

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>
#include <vector>
using namespace std;
#define N 60900
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
int dp[N],v[N],w[N];
int main()
{
int n,m;
while(scanf("%d %d",&n,&m)!=EOF)
{
met(v,0);
met(w,0);
for(int i=1; i<=n; i++)
scanf("%d %d",&w[i],&v[i]);
met(dp,0);
for(int i=1; i<=n; i++)
{
for(int j=m; j>=w[i]; j--)
dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
}
printf("%d\n",dp[m]);
}
return 0;
}

2、Charm Bracelet( poj 3624)简单0-1背包的更多相关文章

  1. POJ 1745 【0/1 背包】

    题目链接:http://poj.org/problem?id=1745 Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

  2. 01背包问题:Charm Bracelet (POJ 3624)(外加一个常数的优化)

    Charm Bracelet    POJ 3624 就是一道典型的01背包问题: #include<iostream> #include<stdio.h> #include& ...

  3. POJ 3624 Charm Bracelet 简单01背包

    题目大意:有n件珠宝,每个珠宝的魅力值为v,重量为w,求在重量不超过m的情况下能达到的最大魅力值. 题目思路:简单的01背包,由于二维数组会超内存所以应该压缩成一维数组. dp[i][j],表示选取i ...

  4. 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 ...

  5. poj 3624 Charm Bracelet 背包DP

    Charm Bracelet Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3624 Descripti ...

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

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

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

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

  8. poj 3624 Charm Bracelet 01背包问题

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

  9. poj 3624 Charm Bracelet(01背包)

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

  10. POJ 3624 Charm Bracelet(01背包)

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

随机推荐

  1. HW4.10

    public class Solution { public static void main(String[] args) { int count = 0; for(int i = 100; i & ...

  2. strip, 关于去除目标文件种的不必要信息

    对于so动态库及可执行文件,可以直接调用不带参数的strip (-s, 即--strip-all)去除大多数不必要的信息.因为so库非常标准,所以strip之后仍然可以进行完美的动态连接:而可执行文件 ...

  3. 问题-Delphi为什么不能连接oracle

    问题现象:delphi 为什么不能连接oracle 问题处理:加一句OraSession1.Options.Net := True;

  4. PHP写日志什么时候需要加锁?

    先分析fwrite,直接找到PHP源代码: static size_t _php_stream_write_buffer(php_stream *stream, const char *buf, si ...

  5. NOIopenjudge 407:Heritage

    总时间限制:  5000ms 内存限制:  65536kB 描述 Your rich uncle died recently, and the heritage needs to be divided ...

  6. eclipse项目出现红色叉叉解决方案

    方法一:导入的文件被删除了.解决方法:右击项目名,在弹出的菜单中选择“Bulid Path”-->“configure build path”-->“Source”,找到已被删除的那个文件 ...

  7. [置顶] mmog游戏开发之业务篇

    这周不是很忙,因为我们的游戏开发了近一年,由于公司的业务调整,在游戏开第二服的时候,老板果断的把项目停到了. 感觉超级的不爽啊.因为这个游戏项目像我的孩子一样和我一样成长,里边的大概的业务逻辑都是偶实 ...

  8. 监控mysql索引使用效率的脚本

      SELECT  t.table_schema AS db,  t.table_name   AS tab_name,  s.index_name   AS index_name,  s.colum ...

  9. kcachegrind gui for callgrind

    DocumentationScreenshotsDownload/SourcesLinksRoadmapBugs & Wishes This is the homepage of the pr ...

  10. count(1) count(*)

    mysql from t; +---+ | +---+ | | | | +---+ rows in set (0.00 sec) mysql) from t; +----------+ ) | +-- ...