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. VPN服务器是什么?

    可能很多人听到VPN的第一感觉是它是一个FQ的工具,然而并不是酱紫的. 虚拟专用网(Virtual Private Network,简称VPN),是一种常用于连接中.大型企业或团体与团体间的私人网络的 ...

  2. css总结

    1. css中的role属性 html 里面的 role 本质上是增强语义性,当现有的HTML标签不能充分表达语义性的时候,就可以借助role来说明.通常这种情况出现在一些自定义的组件上,这样可增强组 ...

  3. CoordinatorLayout+TabLayout+ViewPager

    <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.C ...

  4. html+css 技巧

    3.css定义的技巧:[1].为了将来的css代码优化,建议所有的属性上要带上“:” [2].某些html 标签,有自己默认的css属性值,       例如h1 标签就有自己的属性值,自动就是加粗显 ...

  5. SVM学习笔记(一):libsvm参数说明(转)

    LIBSVM 数据格式需要---------------------- 决策属性 条件属性a 条件属性b ... 2 1:7 2:5 ... 1 1:4 2:2 ... 数据格式转换--------- ...

  6. Windows XP SP3下编译安装check-0.10.0

    软件环境:visual studio 2010 cmake-3.6.3-win32-x86 从github.com下载check-0.10.0到本地,解压出目录check-0.10.0 下载cmake ...

  7. Unity 3D

    Assets(模型.贴图.脚本) Library(快捷方式.暂存文件) ProjectSettings(设置信息) Temp(临时文件) Generate Colliders(是否碰撞) Terrai ...

  8. Asp.Net MVC4入门指南(8):给数据模型添加校验器

    在本节中将会给Movie模型添加验证逻辑.并且确保这些验证规则在用户创建或编辑电影时被执行. 保持事情 DRY ASP.NET MVC 的核心设计信条之一是DRY: "不要重复自己(Don’ ...

  9. OPENWRT开始SFTP支持办法

    root@OpenWrt:~# opkg update root@OpenWrt:~# opkg install vsftpd openssh-sftp-server root@OpenWrt:~# ...

  10. Maven pom.xml 配置说明: 打jar包不包括指定资源文件和.class xml,配置不跑testCase,建pom父子项目

    **maven如何配置打jar包时,一些class 或者资源文件不打进来,把classpath的xml文件打进jar <build> <!--针对资源文件--> <res ...