Coins

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5936    Accepted Submission(s): 2458

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
 
Source

代码: 简单的多重背包,但是恶心的地方是m居然可以为负数....是不是很伤不起呀...哈哈

 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
const int maxn=;
struct price
{
int val;
int num;
};
price sta[maxn];
int dp[];
int main()
{
int n,m,i,j,ans;
while(scanf("%d%d",&n,&m),n+m)
{ for(i=;i<n;i++)
scanf("%d",&sta[i].val);
for(ans=i=;i<n ;i++)
{
scanf("%d",&sta[i].num);
ans+=sta[i].val*sta[i].num ;
}
int tem=ans<m?ans:m;
if(tem<)
{
printf("0\n");
continue;
}
memset(dp,-,sizeof(dp[])*(tem+));
dp[]=;
for(i=;i<n;i++)
{
if(sta[i].num*sta[i].val>=tem) //完全背包
{
for(j=sta[i].val ;j<=tem;j++)
{
if(dp[j-sta[i].val]>-&&dp[j]<dp[j-sta[i].val]+sta[i].num)
dp[j]=dp[j-sta[i].val]+sta[i].num;
}
}
else
{
int k=;
while(sta[i].num>=k)
{
for(j=tem ;j>=k*sta[i].val ; j--)
{
if(dp[j-k*sta[i].val]>-&&dp[j]<dp[j-k*sta[i].val]+k)
dp[j]=dp[j-k*sta[i].val]+k;
}
sta[i].num-=k;
k<<=;
} for(j=tem ;j>=sta[i].num ;j--)
{
if(j<sta[i].num*sta[i].val) break;
if(dp[j-sta[i].num*sta[i].val]>-&&dp[j]<dp[j-sta[i].num*sta[i].val]+sta[i].num)
dp[j]=dp[j-sta[i].num*sta[i].val]+sta[i].num;
} }
}
ans=;
for(i=;i<=tem;i++)
{
if(dp[i]!=-)ans++;
}
printf("%d\n",ans);
}
return ;
}

HDUOJ-------2844Coins的更多相关文章

  1. hduoj 1455 && uva 243 E - Sticks

    http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...

  2. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  3. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  4. hdu-oj 1874 畅通工程续

    最短路基础 这个题目hdu-oj 1874可以用来练习最短路的一些算法. Dijkstra 无优化版本 #include<cstdio> #include<iostream> ...

  5. C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...

  6. C++版 - HDUoj 2010 3阶的水仙花数 - 牛客网

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - ...

  7. HDUOJ题目HTML的爬取

    HDUOJ题目HTML的爬取 封装好的exe/app的GitHub地址:https://github.com/Rhythmicc/HDUHTML 按照系统选择即可. 其实没什么难度,先爬下来一个题目的 ...

  8. hduoj 1251 统计难题

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory ...

  9. hduoj 1286 找新朋友

    http://acm.hdu.edu.cn/showproblem.php?pid=1286 找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  10. hduoj 1285 确定比赛名次

    http://acm.hdu.edu.cn/showproblem.php?pid=1285 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory ...

随机推荐

  1. Installing Apache Spark on Ubuntu 16.04

    Santosh Srinivas on 07 Nov 2016, tagged onApache Spark, Analytics, Data Minin I've finally got to a ...

  2. 混沌数学之Chua's circuit(蔡氏电路)

    蔡氏电路(英语:Chua's circuit),一种简单的非线性电子电路设计,它可以表现出标准的混沌理论行为.在1983年,由蔡少棠教授发表,当时他正在日本早稻田大学担任访问学者[1].这个电路的制作 ...

  3. Vue Cli安装以及使用

      因为公司项目要用vue框架,所以会用vue-cli来新建项目.用过vue的都知道,要全局安装vue以及脚手架vue-cli,然后执行vue init webpack projectname来新建v ...

  4. QT QCharts QScatterSeries 空心点阵图,鼠标移动到上面显示数值,鼠标移开数值消失

    在最近接到的需求是这样的,画一个折线图,关键点使用空心的圆点标识出来,鼠标移动到关键点上,显示出当前数值:鼠标移走数值消失. 我们遇到这个需求的时候,第一时间就会想到使用 QLineSeries 画折 ...

  5. AngularJS 用 $http.jsonp 跨域SyntaxError问题

    必须添加参数:callback=JSON_CALLBACK , 才能进success方法,如下: $http.jsonp("https://request.address.json?call ...

  6. C# 中使用 RSA加解密算法

    一.什么是RSA RSA公开密钥密码体制.所谓的公开密钥密码体制就是使用不同的加密密钥与解密密钥,是一种“由已知加密密钥推导出解密密钥在计算上是不可行的”密码体制. 在公开密钥密码体制中,加密密钥(即 ...

  7. IOS系统之蓝牙外接设备

    Ios系统对于蓝牙外接设备在iphone4以前都是蓝牙2.0的时候,需要通过苹果的审核,据统计通过率仅有2%左右,现在蓝牙2.0基本上处于淘汰状态,所以在这里就不考虑了. 现在iphone4s以后的设 ...

  8. JVM总结-内存监视手段及各区域内存溢出解决

    转载:https://blog.csdn.net/xuqu_volition/article/details/53786096 引言 本文仅关注一些常见的虚拟机内存监视手段,以及JVM运行时数据区各个 ...

  9. Opera Unite 用户指南

    Opera Unite 用户指南 1 Opera Unite 简介 Opera Unite is a collaborative technology that allows you to share ...

  10. sqlplus的使用

    1.连接数据库 sqlplus / as sysdba 2.连接到远程数据库 sqlplus 用户名/密码@服务命名 3.遇到&会当成变量,一般是不需要的,可以关掉 SQL> set d ...