POJ 2642 The Brick Stops Here 0-1背包
来源:互联网 发布:mac如何复制文字 编辑:程序博客网 时间:2024/06/08 08:41
poj: http://poj.org/problem?id=2642
大意:
给出n(n<=200)块黄铜合金,还有它们的浓度和价钱。给出若干个个询问使它们在n块中取 M 块 使得这M块合金的浓度在[cMin*M, cMax*M]这个区间内所花费的价格最少。
这里很详细了。。。。http://blog.sina.com.cn/s/blog_9b95c19e010192vl.html
设计状态dp [i][j][v]表示在i个中买不超过价值为v的物品j件。
include<cstdio>const int INF=999999;const int MAXN=20000+10;int w[201],p[201];int dp[21][MAXN];int main(){int N,M;scanf("%d",&N);for(int i=1;i<=N;i++)scanf("%d%d",&w[i],&p[i]);for(int i=0;i<21;i++)for(int j=0;j<MAXN;j++)dp[i][j]=INF;int maxnum= N >20? 20: N;dp[0][0]=0;for(int i=1;i<=N;i++){for(int j=20000;j>=w[i];j--)for(int k=1;k<=maxnum;k++)if(dp[k-1][j - w[i] ]!=INF)dp[k][j] = dp[k][j] < ( dp[k-1][j - w[i] ]+ p[i] )? dp[k][j] : ( dp[k-1][j - w[i] ]+ p[i] );}int kase;scanf("%d",&kase);for(int ri=0;ri<kase;ri++){int L,R;scanf("%d%d%d",&M,&L,&R);L*=M;R*=M;int ans=INF;for(int i=L;i<=R;i++)if(ans > dp[M][i] )ans=dp[M][i];if(ans==INF)printf("impossible\n");elseprintf("%d\n",ans);}}
- poj 2642 The Brick Stops Here(二维0/1背包)
- POJ 2642 The Brick Stops Here 0-1背包
- POJ 2642 The Brick Stops Here(01背包)
- poj 2642 The Brick Stops Here(01背包)
- POJ 2642 The Brick Stops Here(01背包问题)
- The Brick Stops Here dp 01背包
- Hoj 1488 The Brick Stops Here
- ZOJ 1853 || HOJ 1388 The Brick Stops Here
- zoj3299 Fall the Brick
- POJ 3260 The Fewest Coins(0-1背包 多重背包)
- zoj 3299 Fall the Brick
- poj 3624 (0-1背包)
- POJ 1837(0-1背包)
- POJ 3624 【0-1背包】
- 0 1 背包 poj 3624
- POJ 3093 Margaritas on the River Walk 0-1背包好题
- POJ 3093 Margaritas on the River Walk (0-1背包变形)
- POJ 3211 Washing Clothes (分组背包+0/1背包)
- C# 中Textbox 滚动到最后
- 用队列对扑克牌排序
- (解决办法) UISearchBar 可以呼唤出键盘但无法输入
- N!
- 【IT面试题】字符串
- POJ 2642 The Brick Stops Here 0-1背包
- 沧州达州1384431851796
- 我好像忘记了点什么
- 台州阜康1384431899062
- hdu 1010 Tempter of the Bone
- 洪湖铜川1384431944625
- 肇庆凌源1384431848416
- OpenCV x64 vs2010 下打开摄像头录制视频写成avi(代码为转载)
- 襄樊和田1384431857947