POJ1742:Coins(多重背包)
Description
You are to write a program which reads n,m,A1,A2,A3...An and C1,C2,C3...Cn corresponding to the number of Tony's coins of value A1,A2,A3...An then calculate how many prices(form 1 to m) Tony can pay use these coins.
Input
Output
Sample Input
3 10
1 2 4 2 1 1
2 5
1 4 2 1
0 0
Sample Output
8
4
这道题与杭电的一道题的题意是相同的,之所以拿出来是因为杭电那道题的代码在这里过不了,所以贴一个新的代码
#include <stdio.h>
#include <algorithm>
#include <string.h> int dp[100005];
int sum[100005];
int v[105],c[105]; int main()
{
int i,j,k,n,m;
while(~scanf("%d%d",&n,&m),n+m)
{
for(i = 1;i<=n;i++)
scanf("%d",&v[i]);
for(i = 1;i<=n;i++)
scanf("%d",&c[i]);
memset(dp,0,sizeof(dp));
dp[0] = 1;
int ans = 0;
for(i=1;i<=n;i++)
{
memset(sum,0,sizeof(sum));
for(j = v[i];j<=m;j++)
{
if(!dp[j] && dp[j-v[i]] && sum[j-v[i]]<c[i])
{
dp[j] = 1;
sum[j] = sum[j-v[i]]+1;
ans++;
}
}
}
printf("%d\n",ans);
} return 0;
}
POJ1742:Coins(多重背包)的更多相关文章
- POJ1742 Coins[多重背包可行性]
Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 34814 Accepted: 11828 Descripti ...
- $POJ1742\ Coins$ 多重背包+贪心
Vjudge传送门 $Sol$ 首先发现这是一个多重背包,所以可以用多重背包的一般解法(直接拆分法,二进制拆分法...) 但事实是会TLE,只能另寻出路 本题仅关注“可行性”(面值能否拼成)而不是“最 ...
- POJ 3260 The Fewest Coins(多重背包+全然背包)
POJ 3260 The Fewest Coins(多重背包+全然背包) http://poj.org/problem?id=3260 题意: John要去买价值为m的商品. 如今的货币系统有n种货币 ...
- HDU-2844 Coins(多重背包)
Problem Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. On ...
- POJ3260——The Fewest Coins(多重背包+完全背包)
The Fewest Coins DescriptionFarmer John has gone to town to buy some farm supplies. Being a very eff ...
- POJ 1742 Coins(多重背包, 单调队列)
Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...
- HDU2844 Coins 多重背包
Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDu -2844 Coins多重背包
这道题是典型的多重背包的题目,也是最基础的多重背包的题目 题目大意:给定n和m, 其中n为有多少中钱币, m为背包的容量,让你求出在1 - m 之间有多少种价钱的组合,由于这道题价值和重量相等,所以就 ...
- hdu2844 & poj1742 Coin ---多重背包--两种方法
意甲冠军:你有N种硬币,每个价格值A[i],每个号码C[i],要求. 在不超过M如果是,我们用这些硬币,有多少种付款的情况下,.那是,:1,2,3,4,5,....,M这么多的情况下,,你可以用你的硬 ...
随机推荐
- HDU 4810 这道题 是属于什么类型?
统计每一位出现1的个数 求组合数 直接贴代码 #include <iostream> #include <cstdio> #include <cmath> #in ...
- 慕课linux学习笔记(六)常用命令(3)
Find 命令 #搜索文件 Find [搜索范围] [搜索条件] e.g. find / -name isnstall.log 搜索速度会非常慢 避免大范围搜索,会非常耗费系统资源 Find是在系统当 ...
- django的model对象转化成dict
今天发现一个掉渣天的方法,Django的forms包里面有一个方法:model_to_dict(),它可以将一个model对象转化成dict. In [1]: from apps.dormitory. ...
- Ubuntu下给Sublime Text 3添加用python3运行文件
Ubuntu14.04: 菜单栏:Tools-Build System-New Build System { "cmd": ["python3", " ...
- ACM ICPC Team
Link: https://www.hackerrank.com/challenges/acm-icpc-team/submissions/code/11617807 def count_max_to ...
- 使用Map/MapWhen扩展方法
使用Map/MapWhen扩展方法 .NET Core中间件的注册和管道的构建(3) ---- 使用Map/MapWhen扩展方法 0x00 为什么需要Map(MapWhen)扩展 如果业务逻辑比较简 ...
- Scala学习笔记--隐式转换
隐式转换的规则:1.无歧义规则:隐式转换唯有不存在其他可插入转换的前提下才能插入 若编译器有两种方法修正x+y 如convert1(x)+y,convert2(x)+y,会报错2.单一调用规则:只尝 ...
- Form表单插件jquery.form.js
常常使用到这个插件,但是老忘记怎么使用,现在对大家写的进行一定的整合. 使用插件实例: 一般的使用方法 <!-- 引入jquery文件 --> <script src="h ...
- Extjs4.0.7 MVC Architecture异常
uncaught exception: Ext.Loader is not enabled, so dependencies cannot be resolved dynamically. Mi ...
- cf C. Cupboard and Balloons
http://codeforces.com/contest/342/problem/C #include <cstdio> #include <cstring> #includ ...