http://www.cnblogs.com/ACMan/archive/2012/08/14/2637437.html

#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <cctype>
#include <vector>
#include <iterator>
#include <set>
#include <map>
#include <sstream>
using namespace std; #define mem(a,b) memset(a,b,sizeof(a))
#define pf printf
#define sf scanf
#define spf sprintf
#define pb push_back
#define debug printf("!\n")
#define MAXN 1010
#define MAX(a,b) a>b?a:b
#define blank pf("\n")
#define LL long long
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define pqueue priority_queue
#define INF 0x3f3f3f3f int n,T; const int mx = ; int dp[],f[],w[],c[]; void zobag(int value,int weight)
{
for(int v = mx;v>=weight;v--)
{
dp[v] = min(dp[v],dp[v-weight]+value);
}
} void cmbag(int value,int weight)
{
for(int v = weight;v<=mx;v++)
{
dp[v] = min(dp[v],dp[v-weight]+value);
}
} void fcmbag(int value,int weight)
{
for(int v = weight;v<=mx;v++)
{
f[v] = min(f[v],f[v-weight]+value);
//pf("v%d f%d\n",v,f[v]);
}
} void mubag(int weight,int amount)
{
if(weight*amount >= mx)
{
cmbag(,weight);
return;
}
int k = ;
while(k < amount)
{
//pf("amt%d\n",amount);
//pf("k%d\n",k);
zobag(k,k*weight);
amount-=k;
k*=;
}
zobag(amount,amount*weight);
} int main()
{
int i,j;
while(~sf("%d%d",&n,&T))
{
mem(dp,INF);
mem(f,INF);
dp[]=;
for(i=;i<n;i++)
{
sf("%d",&w[i]);
}
for(i=;i<n;i++)
{
sf("%d",&c[i]);
}
for(i=;i<n;i++)
{
mubag(w[i],c[i]);
}
f[]=;
for(i=;i<n;i++)
{
fcmbag(,w[i]);
}
int ans = INF;
for(i=;i<mx-T;i++)
{
ans = min(ans,dp[i+T]+f[i]);
}
if(ans == INF) ans = -;
pf("%d\n",ans);
}
return ;
}

poj 3260 最少硬币(01+多重+完全背包)的更多相关文章

  1. POJ 3260 The Fewest Coins(多重背包+全然背包)

    POJ 3260 The Fewest Coins(多重背包+全然背包) http://poj.org/problem?id=3260 题意: John要去买价值为m的商品. 如今的货币系统有n种货币 ...

  2. POJ 3260 The Fewest Coins(完全背包+多重背包=混合背包)

    题目代号:POJ 3260 题目链接:http://poj.org/problem?id=3260 The Fewest Coins Time Limit: 2000MS Memory Limit: ...

  3. POJ 3260 The Fewest Coins 最少硬币个数(完全背包+多重背包,混合型)

    题意:FJ身上有各种硬币,但是要买m元的东西,想用最少的硬币个数去买,且找回的硬币数量也是最少(老板会按照最少的量自动找钱),即掏出的硬币和收到的硬币个数最少. 思路:老板会自动找钱,且按最少的找,硬 ...

  4. POJ 3260 The Fewest Coins(多重背包问题, 找零问题, 二次DP)

    Q: 既是多重背包, 还是找零问题, 怎么处理? A: 题意理解有误, 店主支付的硬币没有限制, 不占额度, 所以此题不比 1252 难多少 Description Farmer John has g ...

  5. POJ 2392 Space Elevator(贪心+多重背包)

    POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...

  6. POJ 3211 Washing Clothes(01背包)

    POJ 3211 Washing Clothes(01背包) http://poj.org/problem?id=3211 题意: 有m (1~10)种不同颜色的衣服总共n (1~100)件.Dear ...

  7. POJ 1014 Dividing (多重可行性背包)

    题意 有分别价值为1,2,3,4,5,6的6种物品,输入6个数字,表示相应价值的物品的数量,问一下能不能将物品分成两份,是两份的总价值相等,其中一个物品不能切开,只能分给其中的某一方,当输入六个0是( ...

  8. The Fewest Coins POJ - 3260

    The Fewest Coins POJ - 3260 完全背包+多重背包.基本思路是先通过背包分开求出"付出"指定数量钱和"找"指定数量钱时用的硬币数量最小值 ...

  9. BZOJ_1042_[HAOI2008]硬币购物_容斥原理+背包

    BZOJ_1042_[HAOI2008]硬币购物_容斥原理+背包 题意: 硬币购物一共有4种硬币.面值分别为c1,c2,c3,c4.某人去商店买东西,去了tot次.每次带di枚ci硬币,买s i的价值 ...

随机推荐

  1. 洛谷P4220 [WC2018]通道(边分治+虚树)

    题面 传送门 题解 代码不就百来行么也不算很长丫 虽然这题随机化贪心就可以过而且速度和正解差不多不过我们还是要好好学正解 前置芝士 边分治 米娜应该都知道点分治是个什么东西,而边分治,顾名思义就是对边 ...

  2. Python 中当前位置以及目录文件遍历操作

    Python 中当前位置以及目录文件遍历操作 当前位置 print(os.path.dirname(__file__)) 其中 dirname 会选择目录(文件夹),"__file__&qu ...

  3. JMeter—断言

    断言用来对服务器的响应数据做验证,常用的断言是响应断言,支持正则表达式. 一.BeanShell Assertion 用来访问JMeter的属性: log对象,可以利用此对象写日志 SampleRes ...

  4. [译文]casperjs使用说明-使用命令行

    使用命令行 Casperjs使用内置的phantomjs命令行解析器,在cli模块里,它传递参数位置的命名选项 但是不要担心不能熟练操控CLI模块的API,一个casper实例已经包含了cli属性,允 ...

  5. js 鼠标拖拽效果实现

    效果: 源码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  6. 2018年10月19 手记 - 身为开发者的我de窘境

    从10月1国庆过完节回来,那已经是7号了,之后便开始紧锣密鼓的筹划着接下来11月份的公司组织的对外活动,这边新来的产品对产品或者说对任务很是负责,并且策划了很多的方案,并且乐意站在我们开发的角度上去考 ...

  7. Selenium三种等待元素的方式及代码,需要特别注意implicitlyWait的用法

    一.显式等待 1.显式等待: 就是明确的要等到某个元素的出现或者是某个元素的可点击等条件,等不到,就一直等,除非在规定的时间之内都没找到,那么就跳出Exception. 2.代码: new WebDr ...

  8. Rstudio所有快捷键 “原版+中文” 整理

  9. Q767 重构字符串

    给定一个字符串S,检查是否能重新排布其中的字母,使得两相邻的字符不同. 若可行,输出任意可行的结果.若不可行,返回空字符串. 示例 1: 输入: S = "aab" 输出: &qu ...

  10. archlinux安装tftp

    1. 安装  [guo@archlinux ~]$ sudo pacman -S tftp-hpa 2. 启用  [guo@archlinux ~]$ systemctl start tftpd.se ...