白书P60 - 硬币问题

完全背包、DP

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define INF 0x3f3f3f3f
#define N 1010 int n,s;
int w[N]; //w表示n种硬币的面值
int dp1[N]; //dp1[j]表示刚好凑足j的最少硬币数
int dp2[N]; //dp2[j]表示刚好凑足j的最多硬币数 int main()
{
int i,j;
while(scanf("%d%d",&n,&s)!=EOF)
{
memset(dp1,INF,sizeof(dp1));
memset(dp2,-INF,sizeof(dp2));
dp1[]=;
dp2[]=; for(i=;i<=n;i++)
{
scanf("%d",&w[i]);
} for(i=;i<=n;i++)
{
for(j=w[i];j<=s;j++)
{
dp1[j]=min(dp1[j],dp1[j-w[i]]+);
dp2[j]=max(dp2[j],dp2[j-w[i]]+);
}
}
cout<<dp1[s]<<' '<<dp2[s]<<endl;
}
return ;
}

白书P60 - 硬币问题的更多相关文章

  1. 白书P61 - 点集配对问题

    白书P61 - 点集配对问题 状压DP #include <iostream> #include <cstdio> #include <cstring> using ...

  2. poj2991 Crane(线段树+集合)白书例题

    题目大意:起重机有n节,题目给出要调节的k节,每节调节成x度,求最后底部的起重机的坐标(最顶上的起点为(0,0)). 分析:一开始我看白书,看不懂他那个向量旋转的坐标是怎么来的,翻了很多博客,才发现, ...

  3. Uva10474-STL水题-白书

    白书的一道水题.话说好久没认真做难题了.今天出了排名,所有队伍里倒数第一啊! 代码没什么可说的了. #include <algorithm> #include <cstring> ...

  4. UVA大模拟代码(白书训练计划1)UVA 401,10010,10361,537,409,10878,10815,644,10115,424,10106,465,10494

    白书一:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=64609#overview 注意UVA没有PE之类的,如果PE了显示WA. UVA ...

  5. 《白书》上线段树RMQ的实现

    白书上的线段树RMQ实现,自己重写了一遍: #include <bits/stdc++.h> using namespace std; const int MAXN=1<<17 ...

  6. la3523 白书例题 圆桌骑士 双联通分量+二分图

    具体题解看大白书P316 #include <iostream> #include <algorithm> #include <vector> #include & ...

  7. [tem]线段树(白书版)

    个人感觉有点坑 add用的标记永久化 set用的标记下传 #include <iostream> #include <cstdio> #include <algorith ...

  8. 白书 4.1.2 模运算的世界 P291

    1.逆元 这里有个注意事项要说,就是当要求 (a-b)%m 的时候要注意不能直接 (a%m-b%m)%m 原因是得出的值有可能是负数,所以 (a%m-b%m+m)%m 才是正确的. //x,y是引用 ...

  9. (白书训练计划)UVa 120 Stacks of Flapjacks(构造法)

    题目地址:UVa 120 水题. 从最大的開始移,每次都把大的先翻到最上面,再翻到以下. 代码例如以下: #include <iostream> #include <cstdio&g ...

随机推荐

  1. Config spec rules for elements in subbranches

    Quote from:  Config spec rules for elements in subbranches The following is an example of a config s ...

  2. (转)使用inotify、inotify_add_watch、inotify_rm_watch、read编写监控程序

    转自:http://blog.csdn.net/myarrow/article/details/7096460 inotify是什么 inotify是文件系统变化通知机制,在监听到文件系统变化后,会向 ...

  3. 九度OJ 1385 重建二叉树

    题目地址:http://ac.jobdu.com/problem.php?pid=1385 题目描述: 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都 ...

  4. HDOJ 1042 N! -- 大数运算

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1042 Problem Description Given an integer N(0 ≤ N ≤ 1 ...

  5. opensuse13.1 双屏幕扩展

    最近搞一项j2eeweb工程,想要使用Linux平台编写程序.对比Ubuntu 14.04.Redhat.openSUSE,选择了最后这个. 安装的时候将/boot只分了100M,后来空间不足软件都安 ...

  6. Cassandra1.2文档学习(9)—— 数据写入

    数据参考:http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html#cassandra/dml/manage_dml ...

  7. PHP学习心得(三)——处理表单

    表单的任何元素都在 PHP 脚本中自动生效. 一个简单的 HTML 表单: <form action="action.php" method="post" ...

  8. struts2 修改action的后缀

    struts2 修改action的后缀 struts2 的默认后缀是 .action 虽然很直观,但是很烦琐.很多人喜欢将请求的后缀改为 .do 在struts2中修改action后缀有两种比较简单的 ...

  9. 2.Hashing

    散列法(Hashing)或哈希法是一种将字符组成的字符串转换为固定长度(一般是更短长度)的数值或索引值的方法,称为散列法,也叫哈希法.由于通过更短的哈希值比用原始值进行数据库搜索更快,这种方法一般用来 ...

  10. iOS实现地图半翻页效果--老代码备用参考

    // Curl the image up or down CATransition *animation = [CATransition animation]; [animation setDurat ...