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. CentOS 中卸载 RPM 包文件

    CentOS 中卸载 RPM 包文件 一.原由 因为之前卸载 openvas 这个工具,使用了 find / -name "openvas"-exec rm -rf {} \ ; ...

  2. shell 常用命令集合

    grep -i 忽略大小写 -I 跳过二进制文件 -c 计算数量 -n 显示行号 -R 递归 -v 不匹配某个关键字 常用组合命令 grep -iIRn keyword * 搜索含有该 keyword ...

  3. vue-cli中的webpack打包配置

    如下: assetsSubDirectory: 'static', assetsPublicPath: '/projectName/', 其中assetsSubDirectory是代表服务器上的实际路 ...

  4. BZOJ 2457 双端队列

           Sherry 现在碰到了一个棘手的问题,有N个整数需要排序.        Sherry 手头能用的工具就是若干个双端队列.        她需要依次处理这 N 个数,对于每个数, Sh ...

  5. css提取数据2个常用方法

    提取标签里的内容 所谓数据就是HTML里标签的内容,如下面红色字体,就是标签内容 <title>我只是个实验 - SCRAPY</title> 提取标签里的数据,标签可以是ti ...

  6. Emma姐

  7. Rancher 1.6 版本 只能在 linux 下用

    实际操作 启动 , 访问方式 : 在启动过程中会发现没有 image , 然后自动下载 ( 执行 docker pull 命令 ) docker run --rm --privileged -v /v ...

  8. MySQL子查询subquery

    子查询(Subquery)是指出现在其他SQL语句内的SELECT子句. 例如: select * from t1 where col1=(select col2 from t2); 其中select ...

  9. RequireJs学习笔记之Define a Module

    简单的键值对定义define({    color: "black",    size: "unisize"}); 如果一个模块没有任何依赖,又需要做用一个函数 ...

  10. 开启Unity项目中VS工程的属性面板

    https://www.cnblogs.com/CodeGize/p/7859656.html Unity生成的VS工程一般是无法打开属性面板的.但是事实上,如果使用VS for unity,通过配置 ...