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的价值 ...
随机推荐
- 洛谷P4931 情侣?给我烧了!(加强版)(组合数学)
题面 传送门 题解 首先我们算出刚好有\(k\)对情侣的方案数 从\(n\)对情侣中选出\(k\)对,方案数为\({n\choose k}\) 从\(n\)排座位中选出\(k\)排,方案数为\({n\ ...
- objectARX加载lisp函数、源码的一种方式
//感谢高飞鸟highflybird版主的思路以及研究. //先声明非公开函数acedEvaluateLisp extern int acedEvaluateLisp(const ACHAR*,str ...
- Linux 下四条高大命令(计划360检测脚本)
查看进程,按内存从大到小 ps -e -o "%C : %p : %z : %a"|sort -k5 -nr 查看进程,按CPU利用率从大到小排序 ps -e -o "% ...
- iOS tableview性能优化及分析
1.最常用的就是cell的重用, 注册重用标识符 每次滑动cell时需要先去缓存池中寻找可循环利用的cell,如果没有则再重新创建cell 2.减少cell中控件的数量 view对象尽量缩减控件的数量 ...
- C#使用Redis的基本操作
一,引入dll 1.ServiceStack.Common.dll 2.ServiceStack.Interfaces.dll 3.ServiceStack.Redis.dll 4.ServiceSt ...
- PPT免费模板网站
OfficePlus|微软PPT官方模版库 优品PPT 稻壳儿
- awk练习
首先,了解awk的运行格式 awk '条件类型1{动作1} 条件类型2{动作2} ...' filename 1. [root@server3 mnt]# cat passwd root x 0 0 ...
- JS实现跨域请求数据--CORS
https://www.cnblogs.com/cjw-ryh/p/7674038.html?utm_source=debugrun&utm_medium=referral
- sql语句之group_concat函数
MySQL中group_concat函数 完整的语法如下: group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔 ...
- request.upload.addEventListener in not a function。
本人在使用vue开发一套后台系统时,碰到了一个上传文件的需求,因为平时做的上传是使用ajax的方式来进行上传. 现在是使用axios来进行上传,方式没有什么改变: npm i axios 直接上 ...