Description

Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are selling variously for $1, $2, and $3. Farmer John has exactly $5 to spend. He can buy 5 tools at $1 each or 1 tool at $3 and an additional 1 tool at $2. Of course, there are other combinations for a total of 5 different ways FJ can spend all his money on tools. Here they are:

  1. 1 @ US$3 + 1 @ US$2

  2. 1 @ US$3 + 2 @ US$1

  3. 1 @ US$2 + 3 @ US$1

  4. 2 @ US$2 + 1 @ US$1

  5. 5 @ US$1

Write a program than will compute the number of ways FJ can spend N dollars (1 <= N <= 1000) at The Cow Store for tools on sale with a cost of $1..$K (1 <= K <= 100).

Input

A single line with two space-separated integers: N and K.

Output

A single line with a single integer that is the number of unique ways FJ can spend his money.

Sample Input

  1. 5 3

Sample Output

  1. 5

一看完全背包, 套了模板, 很遗憾wa了, 想了想,不明所以, 搜了下题解, 居然说是因为结果太大, 看看数据似乎是这样的, 据说是两位数存就可以, 结果写完提交,果断AC
 
  1. #include <iostream>
  2. #include <queue>
  3. #include <cmath>
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <cstdlib>
  7. #include <stack>
  8. #include <vector>
  9. #include <algorithm>
  10.  
  11. using namespace std;
  12.  
  13. #define N 2100
  14. #define met(a,b) (memset(a,b,sizeof(a)))
  15. typedef long long LL;
  16.  
  17. LL dp[N][];
  18.  
  19. int main()
  20. {
  21. int n, m;
  22.  
  23. while(scanf("%d%d", &n, &m)!=EOF)
  24. {
  25. int i, j;
  26.  
  27. met(dp, );
  28.  
  29. dp[][] = ;
  30. for(i=; i<=m; i++)
  31. for(j=i; j<=n; j++)
  32. {
  33. dp[j][] += dp[j-i][];
  34. dp[j][] += dp[j-i][];
  35. dp[j][] += dp[j][]/;
  36. dp[j][] %= ;
  37. }
  38.  
  39. if(dp[n][]==)
  40. printf("%I64d\n", dp[n][]);
  41. else
  42. {
  43. printf("%I64d%015I64d\n", dp[n][], dp[n][]);
  44. }
  45. }
  46.  
  47. return ;
  48. }

参考http://www.cnblogs.com/kuangbin/archive/2012/09/20/2695165.html

(完全背包 大数)Dollar Dayz (POJ 3181)的更多相关文章

  1. Dollar Dayz POJ - 3181

    解法 完全背包+大数...不想写大数了放个python得了 代码 dp=[0 for i in range(2000)] n,k=map(int,input().split()) num=[i for ...

  2. DP:Dollar Dayz(POJ 3181)

    一道高精度DP 题目大意,换工具,有m块钱,有k种价值的物品,(1...k),求一共有多少种换法 这一题就是完全背包,现在这种完全背包对我来说就是水题了, 状态转移方程闭着眼睛写dp[j]+=dp[j ...

  3. POJ 3181 Dollar Dayz(全然背包+简单高精度加法)

    POJ 3181 Dollar Dayz(全然背包+简单高精度加法) id=3181">http://poj.org/problem?id=3181 题意: 给你K种硬币,每种硬币各自 ...

  4. POJ 3181 Dollar Dayz && Uva 147 Dollars(完全背包)

    首先是 Uva 147:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_p ...

  5. POJ 3181 Dollar Dayz 【完全背包】

    题意: 给出两个数,n,m,问m以内的整数有多少种组成n的方法完全背包+大数划分 思路: dp[i][j] := 用i种价格配出金额j的方案数. 那么dp[i][0] = 1,使用任何价格配出金额0的 ...

  6. poj 3181 Dollar Dayz(完全背包)

    Dollar Dayz Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5419   Accepted: 2054 Descr ...

  7. Dollar Dayz(大数母函数,高低位存取)

    Dollar Dayz Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5655   Accepted: 2125 Descr ...

  8. poj3181 背包+大数

    http://poj.org/problem?id=3181 Dollar Dayz Time Limit: 1000MS   Memory Limit: 65536K Total Submissio ...

  9. poj 3181 Dollar Dayz(求组成方案的背包+大数)

    可能nyist看见加的背包专题我老去凑热闹,觉得太便宜我了.他们新加的搜索专题居然有密码. 都是兄弟院校嘛!何必那么小气. 回到正题,跟我写的上一篇关于求组成方案的背包思路基本一样,无非就是一个二维费 ...

随机推荐

  1. sql查询当天,一周,一个月数据的语句

    --查询当天:  select * from info where DateDiff(dd,datetime,getdate())=0 --查询24小时内的: select * from info w ...

  2. Postgresql死锁处理

    今天遇到Postgresql的一个问题,部分表记录的update一直无效报错,初步判断为锁表,赶紧进行解决. 1. 查询死锁进程列表 select * from pg_stat_activity wh ...

  3. extern关键字

    1.extern "C" void func(){...} extern可以置于变量或者函数前,以标示变量或者函数的定义在别的文件中,提示编译器遇到此变量和函数时在其他模块中寻找其 ...

  4. iOS常用网络库之AFNetWorking

    简介 ​     `AFNetworking`是iOS开发网络API中最常用的第三方库,`github`中的`star`数充分说明了它在iOS开发中第三方库中的江湖地位  github地址:[AFNe ...

  5. div里面的id与for

    <input class="select" type="checkbox" value="1" id="checkboxjc ...

  6. python函数动态参数详解

    Python的动态参数: 1,参数前一个"*":在函数中会把传的参数转成一个元组. def func (*args): print(args) func(123,1,2,'a') ...

  7. EF MYSQL 不能选择实体框架版本

    web.config文件里面加如下配置,然后编译 <provider invariantName="MySql.Data.MySqlClient" type="My ...

  8. MVC 过滤器 构建会员是否登录

    使用环境:在后台管理或者前台有会员中心的情况下使用 使用方式:这是一个用户中心的控制器 我给用户中心主页增加一个特性 [AccountFilter]这是一个过滤器的名字 public class Ac ...

  9. 前端自动构建工具@gulp入门

    gulp是一个自动化的前端工具.它可以利用自身的插件来实现一些功能,如sass.less编译:浏览器自动刷新,文件压缩.重命名.代码校验(个人使用sublime的插件进行校验)等功能.当然这些功能也可 ...

  10. 升级到VS2012,reportViewer无法使用

    最近公司的开发环境升级到VS2012,为了电脑能够快点,我重装系统,只装VS2012没有装VS2010.这个时候问题来了,原本用VS2010开发的项目用VS2012编译能通过,运行时包下图错: 为了解 ...