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. 人不能同时在两个地方做猪(Scrum Team)

    在一个神奇的国度里生活着许多动物, 其中有猪, 鸡, 和鹦鹉. 它们每天搞头脑风暴, 琢磨如何创业, 最后鹦鹉提议它们合伙开一个早餐店: 具体分工如下: 猪: 提供猪肉, 做熏猪肉 (bacon) 鸡 ...

  2. cmd操作oracle

    利用cmd的操作命令导出,详情如下(备注:方法二是转载网上的教程):1:G:\Oracle\product\10.1.0\Client_1\NETWORK\ADMIN目录下有个tnsname.ora文 ...

  3. Thread.sleep

    Thread.sleep() The current thread changes state from Running to Waiting/Blocked as shown in the diag ...

  4. fc_net.py cs231n

    n如果有错误,欢迎指出,不胜感激 import numpy as np from cs231n.layers import * from cs231n.layer_utils import * cla ...

  5. 【水滴石穿】mobx-todos

    我觉得代码在有些程序员手里,就好像是画笔,可以创造很多东西 不要觉得创意少就叫没有创意,每天进步一点点,世界更美好 首先源码地址为:https://github.com/byk04712/mobx-t ...

  6. MaxCompute 助力衣二三构建智能化运营工具

    摘要:本文由衣二三CTO程异丁为大家讲解了如何基于MaxCompute构建智能化运营工具.衣二三作为亚洲最大的共享时装平台,MaxCompute是如何帮助它解决数据提取速度慢.数据口径差异等问题呢?程 ...

  7. SQL知识总结(1)

    什么是数据库: sql组成: DDL:数据定义语句,有CREATE/DROP等: DML:数据操作语句,有DELETE/UPDATE/INSERT/INSERT等; DQL:数据查询语句,有SELEC ...

  8. 关于JSP的淘汰问题(转)

    来源:http://1t.click/peD 大中型公司需要专业人才,小公司需要全才,但是对于个人职业发展来说,我建议是分开.你要是这辈子就吃java这碗饭,就不要去研究什么css,js等等. 把你的 ...

  9. 19-2 from和modelform的用法和介绍

    一 form 1. form的作用 1. 生成HTML代码 2. 帮我们做数据有效性的校验 3. 保留上次输入内容,显示错误提示 2. form组件校验数据有效性   1. 内置的校验规则 1. re ...

  10. 2019-4-29-dotnet-core-通过-frp-发布自己的网站

    title author date CreateTime categories dotnet core 通过 frp 发布自己的网站 lindexi 2019-04-29 12:26:45 +0800 ...