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 @ US$3 + 1 @ US$2

1 @ US$3 + 2 @ US$1

1 @ US$2 + 3 @ US$1

2 @ US$2 + 1 @ US$1

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

5 3

Sample Output

5

一看完全背包, 套了模板, 很遗憾wa了, 想了想,不明所以, 搜了下题解, 居然说是因为结果太大, 看看数据似乎是这样的, 据说是两位数存就可以, 结果写完提交,果断AC
 
#include <iostream>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm> using namespace std; #define N 2100
#define met(a,b) (memset(a,b,sizeof(a)))
typedef long long LL; LL dp[N][]; int main()
{
int n, m; while(scanf("%d%d", &n, &m)!=EOF)
{
int i, j; met(dp, ); dp[][] = ;
for(i=; i<=m; i++)
for(j=i; j<=n; j++)
{
dp[j][] += dp[j-i][];
dp[j][] += dp[j-i][];
dp[j][] += dp[j][]/;
dp[j][] %= ;
} if(dp[n][]==)
printf("%I64d\n", dp[n][]);
else
{
printf("%I64d%015I64d\n", dp[n][], dp[n][]);
}
} return ;
}

参考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. cocos2d-x 观察者设计模式

    1.参考文章  http://blog.csdn.net/vanquishedzxl/article/details/23616535 class HelloWorld : public cocos2 ...

  2. struts2配置文件中Action中的各属性的含义

    StrutsApacheBeanJSPServlet attribute:      这个属性用来指定ActionForm保存到指定上下文时所使用的属性名.如果不指定attribute属性的值,将使用 ...

  3. 利用Unity制作“表”

    一枚小菜鸟   目前没发现在Unity有其他路径制作类似于c# WinForm中的表:但是利用Unity自带的UGUI,制作了一张"伪表",具体方案如下: 效果图如下: 步骤: 1 ...

  4. linux替换文件指定字符串前面的内容

    sed 's/.*user_id/user_id/' wechat_log2 > target_log

  5. node.js 基础学习笔记3 -express

    1.工作原理 当通过app.js建立的服务器时,会看到一个简单的页面.返回页面时,浏览器会向服务器发送请求.app会解析请求的路径,调用相应的逻辑,调用对应的视图模板,传递对象数值,最终生成HTML页 ...

  6. 一个div,包含两个div,调整文字位置和div平均分布

    网页中经常会用到,一个div下平均分布两个小的div,两个小的div,显示的内容为图片还比较好处理,显示文字则不好控制效果,今天写了一个如图效果的 html: <div class=" ...

  7. [z]Oracle性能优化-读懂执行计划

    http://blog.csdn.net/lifetragedy/article/details/51320192 Oracle的执行计划   得到执行计划的方式       Autotrace例子 ...

  8. DailyRollingFileAppender的使用

    DailyRollingFileAppender是日志记录软件包Log4J中的一个Appender,它能够按一定的频度滚动日志记录文件. 如果您不熟悉Log4J,建议阅读一下 使用Log4j进行日志记 ...

  9. 服务器Linux系统安全维护基础知识介绍

    事先规划好Linux操作系统的分区 Linux操作系统的分区规划跟微软操作系统的分区规划不同.后者分区规划对于其性能的影响很小.但是Linux操作系统的分区规划则不同,其对服务器的性能影响很大.其实我 ...

  10. 织梦建站:视频弹出播放JS+CSS

    需要 jquery.js 文件,JS代码一定要放在HTM下面,否则没效果罗! CSS代码: 1.fdspbf{ width:650px; height:550px; position:fixed; l ...