http://poj.org/problem?id=2754

先把low--up 转化为0--(up-low)

然后变成背包  背包的关键在于多重背包用二进制优化

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#define LL long long
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int INF=0x3f3f3f3f;
const int N=205;
const int M=100005;
int low[N],up[N],p[N],m[N];
int dp[M];
void pack01(int cost,int weight,int V)
{for(int v=V;v>=cost;--v)dp[v]=max(dp[v],dp[v-cost]+weight);
}
void packComplete(int cost,int weight,int V)
{for(int v=cost;v<=V;++v)dp[v]=max(dp[v],dp[v-cost]+weight);
}
void packMultiple(int cost,int weight,int num,int V)
{if((num+1)*cost>V)packComplete(cost,weight,V);else{int k=1;while(k<=num){pack01(cost*k,weight*k,V);num-=k;k=k<<1;}pack01(cost*num,weight*num,V);}
}
int main()
{//freopen("data.in","r",stdin);int n;while(scanf("%d",&n)!=EOF){int k=0,res=0;for(int i=1;i<=n;++i){scanf("%d %d %d %d",&p[i],&m[i],&low[i],&up[i]);k+=(0-low[i])*m[i];res+=(low[i]-0)*p[i];}memset(dp,0x80,sizeof(dp));dp[0]=0;for(int i=1;i<=n;++i)packMultiple(m[i],p[i],up[i]-low[i],k);printf("%d\n",dp[k]+res);}return 0;
}

  

转载于:https://www.cnblogs.com/liulangye/archive/2013/02/19/2917216.html

poj 2754 Similarity of necklaces 2相关推荐

  1. POJ-2754 Similarity of necklaces 2 区间取下界操作+DP

    这题一个很巧妙的操作就是对一个给定的区间同意将下界拿出来, 然后转化为多重背包问题. 使用二进制优化. 代码如下: #include <cstdlib> #include <cstr ...

  2. POJ 1286 Necklaces of Beads (Burnside定理,有限制型)

    题目链接:http://vjudge.net/problem/viewProblem.action?id=11117 就是利用每种等价情形算出置换节之后算组合数 #include <stdio. ...

  3. 【转载】图论 500题——主要为hdu/poj/zoj

    转自--http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  4. POJ ZOJ题目分类

    POJ,ZOJ题目分类(多篇整合版,分类很细致,全面) 标签: 题目分类POJ整理 2015-04-18 14:44 1672人阅读 评论(0) 收藏 举报 本文章已收录于: 分类: ACM资料(5) ...

  5. POJ,ZOJ题目分类(多篇整合版,分类很细致,全面)

    水题: 3299,2159,2739,1083,2262,1503,3006,2255,3094 初级: 一.基本算法:        (1)枚举 (1753,2965)       (2)贪心(13 ...

  6. POJ 3268 D-Silver Cow Party

    http://poj.org/problem?id=3268 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...

  7. poj 2559 Largest Rectangle in a Histogram 栈

    // poj 2559 Largest Rectangle in a Histogram 栈 // // n个矩形排在一块,不同的高度,让你求最大的矩形的面积(矩形紧挨在一起) // // 这道题用的 ...

  8. POJ 2528 Mayor's posters(线段树)

    题目大意 贴海报.每张海报的高度都是一样的,唯独宽度不一样.每张海报只能占用整数倍的单位线段长度,贴了 n(n<=10000) 张海报之后,有几张能够看见(有一个角能看见这张海报也算被看见了)? ...

  9. POJ 2226 Muddy Fields 最小点覆盖+加建图(好题)

    题目链接 题目一看就是最小点覆盖,这道题与POJ - 3041 算是一类题,但是3041算是一道十分裸的,因为删除的是整行或者整列,所以图其实是现成的,但是本题的难点就在如何建图. 思路:首先还是尽量 ...

  10. poj 2681 字符串

    http://poj.org/problem?id=2681 给你任意长度的字符串,找出两串字符中不相同的字符个数(总数) #include<string> #include<cst ...

最新文章

  1. php 原生查询mongo,PHP操作MongoDB的原生CURD方法
  2. 机器学习数据预处理之缺失值:插值法填充+多项式插值
  3. centos6.5安装remmina rdp
  4. 【线性代数公开课MIT Linear Algebra】 第二十三课 微分方程与exp(At)
  5. Tomcat本地正常!但是部署到服务器后,mysql插入中文乱码问题解决!
  6. Jquery学习总结(7)——JQuery常用的10个方法总结
  7. SDOI2019R1游记
  8. 纯手工打造漂亮的垂直时间轴,使用最简单的HTML+CSS+JQUERY完成100个版本更新记录的华丽转身!...
  9. mycat重启报错Failed to connect to the Wrapper at port解决方法
  10. mergesort java 源码_MergeSort(Java)
  11. 飞鸟尽,良弓藏;狡兔死,走狗烹。
  12. word两种html区别,word文本框有哪两种方式?
  13. 总结定时器设计方法_超实用!网站导航栏设计方法总结
  14. 字符串删除开头部分数字
  15. 图片打不开怎么办?只需这样操作
  16. webgame qlj
  17. 一沓扑克牌中剔除等于13或者相邻之和等于13的扑克牌,剩余多少
  18. 如何用六个步骤封装Python代码包
  19. python写签到软件_第一个实用python程序——自动填写工作日志、签到
  20. 《商务与经济统计》Python实现笔记(三)

热门文章

  1. flink基本原理入门
  2. C++模版类List实现
  3. 首座生态厕所亮相兰州 生物降解“三年不臭”
  4. Android图片控件,跟随列表(recyclerView)的上下滚动而同步平移。
  5. python爬虫问题:error: command 'gcc' failed with exit status 1
  6. 如何使用JMeter来实现更大批量的并发的解决方案(即如何设置controller和Agent)
  7. 94. Binary Tree Inorder Traversal
  8. Open vSwitch实践——VLAN
  9. phpmailer 发送Outlook邮件时535 5.7.3 authentication unsuccessful错误的解决办法 谷歌邮箱 SMTP ERROR: Password command
  10. JS和JS是IE上JavaScript或JScript的缩写。