poj 3260 最少硬币(01+多重+完全背包)
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+多重+完全背包)的更多相关文章
- POJ 3260 The Fewest Coins(多重背包+全然背包)
POJ 3260 The Fewest Coins(多重背包+全然背包) http://poj.org/problem?id=3260 题意: John要去买价值为m的商品. 如今的货币系统有n种货币 ...
- POJ 3260 The Fewest Coins(完全背包+多重背包=混合背包)
题目代号:POJ 3260 题目链接:http://poj.org/problem?id=3260 The Fewest Coins Time Limit: 2000MS Memory Limit: ...
- POJ 3260 The Fewest Coins 最少硬币个数(完全背包+多重背包,混合型)
题意:FJ身上有各种硬币,但是要买m元的东西,想用最少的硬币个数去买,且找回的硬币数量也是最少(老板会按照最少的量自动找钱),即掏出的硬币和收到的硬币个数最少. 思路:老板会自动找钱,且按最少的找,硬 ...
- POJ 3260 The Fewest Coins(多重背包问题, 找零问题, 二次DP)
Q: 既是多重背包, 还是找零问题, 怎么处理? A: 题意理解有误, 店主支付的硬币没有限制, 不占额度, 所以此题不比 1252 难多少 Description Farmer John has g ...
- POJ 2392 Space Elevator(贪心+多重背包)
POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...
- POJ 3211 Washing Clothes(01背包)
POJ 3211 Washing Clothes(01背包) http://poj.org/problem?id=3211 题意: 有m (1~10)种不同颜色的衣服总共n (1~100)件.Dear ...
- POJ 1014 Dividing (多重可行性背包)
题意 有分别价值为1,2,3,4,5,6的6种物品,输入6个数字,表示相应价值的物品的数量,问一下能不能将物品分成两份,是两份的总价值相等,其中一个物品不能切开,只能分给其中的某一方,当输入六个0是( ...
- The Fewest Coins POJ - 3260
The Fewest Coins POJ - 3260 完全背包+多重背包.基本思路是先通过背包分开求出"付出"指定数量钱和"找"指定数量钱时用的硬币数量最小值 ...
- BZOJ_1042_[HAOI2008]硬币购物_容斥原理+背包
BZOJ_1042_[HAOI2008]硬币购物_容斥原理+背包 题意: 硬币购物一共有4种硬币.面值分别为c1,c2,c3,c4.某人去商店买东西,去了tot次.每次带di枚ci硬币,买s i的价值 ...
随机推荐
- 时区缩写 UTC, CST, GMT, CEST 以及转换
UTC是协调世界时(Universal Time Coordinated)英文缩写,是由国际无线电咨询委员会规定和推荐,并由国际时间局(BIH)负责保持的以秒为基础的时间标度.UTC相当于本初子午线( ...
- css3 -webkit-filter
-webkit-filter是css3的一个属性,Webkit率先支持了这几个功能,感觉效果很不错.下面咱们就学习一下filter这个属性吧. 现在规范中支持的效果有: grayscale 灰度 ...
- FPGA基础学习(6) -- 原语
目录 1. IBUF和IBUFDS(IO) 2. IDDR(Input/Output Functions) 3. IBUFG和IBUFGDS(IO) 原语,即primitive.不同的厂商,原语不同: ...
- 做point data的切面的时候的注意事项
正确的顺序应该是: 先导入cell data,再转换为point data,再做切面.结果如下: 如果这里导入cell data以后先做了切面再转换为point data,结果就是这样的: 很明显中间 ...
- PyCharm 通过Github和Git上管理代码
1.最近希望通过github来管理代码,记录下pycharm上的设置,以下是针对windows版本.mac版本略有却别 如图所示 file-settings-Version Control-GitHu ...
- Git命令之回退篇 git revert git reset
Git command之回退篇 欲练回退 必先了解:HEAD.index.WorkingCopy HEAD: 当前所在的分支版本顶端的别名,也就是最新的一次commit. git commit 之后与 ...
- SpringCloud---API网关服务---Spring Cloud Zuul
1.概述 1.1 微服务架构出现的问题 及 解决: 1.1.1 前言 每个微服务应用都提供对外的Restful API服务,它通过F5.Nginx等网络设备或工具软件实现对各个微服务的路由与负载 ...
- nginx常用配置2
## 一.Nginx中虚拟主机配置 ### 1.基于域名的虚拟主机配置 1.修改宿主机的hosts文件(系统盘/windows/system32/driver/etc/HOSTS) linux : ...
- IIS进程池异常崩溃,导致网站 service unavailable,原因排查与记录。
昨晚十点钟的样子,网站崩溃,开始 service unavailable,最近开始业务高峰,心里一惊,麻痹肯定进程池又异常崩溃了.又碰到什么问题?上次是因为一个异步线程的问题,导致了进程池直接崩溃,后 ...
- Jquery执行效率提高的方法
1.选择器性能排行:$("#ID") > $("Tag") > $(".Class") > $("[attrib ...