首页 > 其他分享 >HDU 2844 Coins

HDU 2844 Coins

时间:2022-10-25 17:02:16浏览次数:81  
标签:HDU coins int 2844 Coins A3 A1 xx include


题目链接:​​传送门​​​ 题面:

Problem Description

Whuacmers use coins.They have coins of value A1,A2,A3…An Silverland dollar. One day Hibix opened purse and found there were some coins. He decided to buy a very nice watch in a nearby shop. He wanted to pay the exact price(without change) and he known the price would not more than m.But he didn’t know the exact price of the watch.

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

The input contains several test cases. The first line of each test case contains two integers n(1 ≤ n ≤ 100),m(m ≤ 100000).The second line contains 2n integers, denoting A1,A2,A3…An,C1,C2,C3…Cn (1 ≤ Ai ≤ 100000,1 ≤ Ci ≤ 1000). The last test case is followed by two zeros.

Output

For each test case output the answer on a single line.

Sample Input

3 10
1 2 4 2 1 1
2 5
1 4 2 1
0 0

Sample Output

8
4

题目大意:

你想要买一个东西,你有种硬币,每种硬币的面值为每种硬币的数量为要买的物品价值不超过,要输出之间能支付多少面额

对于的每一种价格都当成一个背包
要把它装满
做多重背包就好了
最后再统计一下能有多少装满的
唯一一点就是这个题要二进制优化

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <vector>
#include <iomanip>
#define
#define
#define

using namespace std;
int n, m, V, w[A], f[A], p[A];

int main() {
while (cin >> n >> V) {
if (!n and !V) break;
for (int i = 1; i <= n; i++) cin >> w[i];
for (int i = 1; i <= n; i++) cin >> p[i];
memset(f, -0x3f, sizeof f); f[0] = 0;
for (int i = 1; i <= n; i++) {
int xx = p[i], k = 1;
while (k < xx) {
for (int j = V; j >= k * w[i]; j--)
f[j] = max(f[j], f[j - k * w[i]] + k);
xx -= k; k <<= 1;
}
for (int j = V; j >= xx * w[i]; j--)
f[j] = max(f[j], f[j - xx * w[i]] + xx);
}
int ans = 0;
for (int i = 1; i <= V; i++)
if (f[i] > 0) ans++;
cout << ans << endl;
}
}


标签:HDU,coins,int,2844,Coins,A3,A1,xx,include
From: https://blog.51cto.com/lyle/5794957

相关文章

  • HDU 1203 I NEED A OFFER!
    题目链接:​​传送门​​题面:INEEDAOFFER!ProblemDescriptionSpeakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了......
  • HDU 1114 Piggy-Bank
    题目链接:​​传送门​​Piggy-BankProblemDescriptionBeforeACMcandoanything,abudgetmustbepreparedandthenecessaryfinancialsupportobtained.Them......
  • HDU 2546 饭卡
    题目链接:​​传送门​​题面:ProblemDescription电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一......
  • HDU 2602 Bone Collector
    题目链接:​​传送门​​​题面:ProblemDescriptionManyyearsago,inTeddy’shometowntherewasamanwhowascalled“BoneCollector”.Thismanliketocollec......
  • HDU2376 Average distance
    题目链接:传送门求树上任意两点间的路径和的平均值非常套路统计每条边被经过多少次就是两边的点数的乘积注意精度就好#include<cstdio>#include<cstring>#include<alg......
  • HDU 1394 Minimum Inversion Number
    题目链接:​​传送门​​求出原数组的逆序对算把一个数从对头拿到队尾的过程中产生的贡献诶我好像昨天做过这个题#include<iostream>#include<cstdio>#include<cstring......
  • HDU 4135 Co-prime
    题目链接:​​传送门​​多组数据问区间内与互质的数的个数区间问题显然要转化成两个区间相减的问题也就是的答案减去的答案这里反过来求不互质的数的个数筛法可以提示我......
  • HDU 3349 Consumer
    ​​题目链接​​题目背景有依赖的背包,下面用我常用的变量和说法。题目大意有个主件和块钱,每个主件都有费用和对应的个附件,附件也有费用与价值,购买主件后才能购买附件,问怎......
  • HDU 1465(错排公式)
    不容易系列之一TimeLimit:2000/1000MS(Java/Others)    MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):9829    AcceptedSubmission(s):......
  • Universal Atomic Swaps: Secure Exchange of Coins Across All Blockchains
    UniversalAtomicSwaps:SecureExchangeofCoinsAcrossAllBlockchainsThyagarajanSAK,MalavoltaG,Moreno-SánchezP.Universalatomicswaps:Secureexc......