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

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 Output5



高精度问题,必须分开保存。

题意:输入n,和k,问将n用1到k这k个数字进行拆分,有多少种拆分方法。例如:

n=5,k=3 则有n=3+2,n=3+1+1,n=2+1+1+1,n=2+2+1,n=1+1+1+1+1这5种拆分方法

附上代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
__int64 a[],b[],inf;
int n,k,i,j;
inf=;
for(i=; i<; i++)
inf*=;
while(~scanf("%d%d",&n,&k))
{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
a[]=;
for(i=; i<=k; i++)
for(j=; j<=n; j++)
{
if(j<i) continue;
b[j]=b[j]+b[j-i]+(a[j]+a[j-i])/inf; //高精度处理
a[j]=(a[j]+a[j-i])%inf;
}
if(b[n]) printf("%I64d",b[n]);
printf("%I64d\n",a[n]);
}
return ;
}

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

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

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

  2. POJ 3181 Dollar Dayz ( 完全背包 && 大数高精度 )

    题意 : 给出目标金额 N ,问你用面额 1~K 拼成 N 的方案有多少种 分析 : 完全背包的裸题,完全背包在 DP 的过程中实际就是列举不同的装填方案数来获取最值的 故状态转移方程为 dp[i] ...

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

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

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

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

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

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

  6. POJ 3181 Dollar Dayz (完全背包,大数据运算)

    题意:给出两个数,n,m,问1~m中的数组成n,有多少种方法? 这题其实就相当于 UVA 674 Coin Change,求解一样 只不过数据很大,需要用到高精度运算... 后来还看了网上别人的解法, ...

  7. POJ 3181 Dollar Dayz(高精度 动态规划)

    题目链接:http://poj.org/problem?id=3181 题目大意:用1,2...K元的硬币,凑成N元的方案数. Sample Input 5 3 Sample Output 5 分析: ...

  8. poj 3181 Dollar Dayz (整数划分问题---递归+DP)

    题目:http://poj.org/problem?id=3181 思路:将整数N划分为一系列正整数之和,最大不超过K.称为整数N的K划分. 递归:直接看代码: 动态规划:dp[i][j]:=将整数i ...

  9. poj 3181 Dollar Dayz

    题意:给定一个数p,要求用K种币值分别为1,2,3...K的硬币组成p,问方案数,1,2,2和2,2,1算一种方案即与顺序无关,n <= 1000,k <= 100// 用完全背包做了 这 ...

随机推荐

  1. farv

    http://weishu.me/ https://github.com/jimupon/VirtualXposed O:  ?  api 26 - vdex N: speed-profile M: ...

  2. 【python之路19】文件操作

    一.打开文件 文件句柄 = open('文件路径', '模式') 打开文件时,需要指定文件路径和以何等方式打开文件,打开后,即可获取该文件句柄,日后通过此文件句柄对该文件操作. 打开文件的模式有: r ...

  3. caffe 的docker安装过程及相关linux操作总结

    一.caffe 和 docker的安装编译 docker pull caffe镜像(注意使用docker安装省去安装CUDA和cudnn的安装.) 安装相关依赖包 安装opencv3(使用源码安装) ...

  4. bnd.bnd属性文件格式

    1.Header以大写字母开头 Bundle-Name: StoreAdminProductsTool 2.Instruction以-和小写字母开头 -sources: true 3. Macro形式 ...

  5. 【Leetcode 二分】 滑动窗口中位数(480)

    题目 中位数是有序序列最中间的那个数.如果序列的大小是偶数,则没有最中间的数:此时中位数是最中间的两个数的平均数. 例如: [2,3,4],中位数是 3 [2,3],中位数是 (2 + 3) / 2 ...

  6. SPSS分析技术:二阶聚类分析;为什么出现大学生“裸贷”业务,因为放贷者知道贷款者还不起

    SPSS分析技术:二阶聚类分析:为什么出现大学生"裸贷"业务,因为放贷者知道贷款者还不起 今天将介绍一种智能聚类法,二阶聚类法,在开始介绍之前,先解答很多人在后台提出的一个疑问:那 ...

  7. Leetcode812.Largest Triangle Area最大三角形面积

    给定包含多个点的集合,从其中取三个点组成三角形,返回能组成的最大三角形的面积. 示例: 输入: points = [[0,0],[0,1],[1,0],[0,2],[2,0]] 输出: 2 解释: 这 ...

  8. (译)Objective-C的动态特性

    这是一篇译文,原文在此,上一篇文章就是受这篇文章启发,这次干脆都翻译过来. 过去的几年中涌现了大量的Objective-C开发者.有些是从动态语言转过来的,比如Ruby或Python,有些是从强类型 ...

  9. jquery on事件

    可以给后添加的动态元素绑定事件

  10. Effective C++: 01让自己习惯C++

    01:视C++为一个语言联邦 1:今天的C++已经是个多重范型编程语言(multiparadigm programming language),一个同时支持过程形式(procedural).面向对象形 ...