http://poj.org/problem?id=3181

Dollar Dayz
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7997   Accepted: 2992

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

Source

   大数加法写成shi我也是很无奈- -,ans的位数写的不对导致部分数据能过让我检查半天。

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
struct Bign
{
int a[];
void out()
{
for(int i=a[];i>=;--i)
printf("%d",a[i]);puts("");
}
}f[];
void add(Bign &e,Bign &x){
int limit=max(e.a[],x.a[]);
e.a[]=limit;
for(int i=;i<=limit;++i)
e.a[i]+=x.a[i];
for(int i=;i<=e.a[];++i)
{
if(e.a[i]>){
e.a[i+]++;
e.a[i]%=;
}
if(e.a[e.a[]+]) e.a[]++;
}
}
int main()
{
int N,K,i,j;
while(cin>>N>>K){
for(i=;i<=N;++i){
memset(f[i].a,,sizeof(f[i].a));
f[i].a[]=;
}
f[].a[]=;
for(i=;i<=K;++i)
for(j=i;j<=N;++j){
add(f[j],f[j-i]);
}
f[N].out();
}
return ;
}

poj3181 背包+大数的更多相关文章

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

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

  2. (完全背包 大数)Dollar Dayz (POJ 3181)

    http://poj.org/problem?id=3181 Description Farmer John goes to Dollar Days at The Cow Store and disc ...

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

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

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

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

  5. Dollar Dayz POJ - 3181

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

  6. dp之完全背包poj3181(高精度背包)

    这个题目要用到大数的加法,其他的,我没有感觉到有什么难想的......比较水的背包题,掠过..... #include<iostream> #include<stdio.h> ...

  7. POJ Dollar Dayz 美元假日(完全背包,常规+大数)

    题意:给出整数n和k,n代表拥有的钱数量,k代表有k种工具,其价钱分别为1~k.求n元能有多少种购买的方案. 思路:k最大有100,数量过大,要用大数.其他的基本和完全背包一样. #include & ...

  8. poj3181 Dollar Dayz ——完全背包

    link:http://poj.org/problem?id=3181 本来很常规的一道完全背包,比较有意思的一点是,结果会超int,更有意思的解决方法是,不用高精度,用两个整型的拼接起来就行了.OR ...

  9. nyoj 1091 还是01背包(超大数dp)

    nyoj 1091 还是01背包 描述 有n个重量和价值分别为 wi 和 vi 的物品,从这些物品中挑选总重量不超过W的物品,求所有挑选方案中价值总和的最大值 1 <= n <=40 1 ...

随机推荐

  1. python线程池/进程池创建

    进程池 import time from concurrent.futures import ProcessPoolExecutor def task(arg): time.sleep(2) prin ...

  2. 用仿ActionScript的语法来编写html5——第五篇,Graphics绘图

    用仿ActionScript的语法来编写html5——第五篇,Graphics绘图 canvas本身就是一个Graphics,可以直接进行绘图在actionscript里面,每个Sprite都有一个G ...

  3. HDU4223:Dynamic Programming?(简单dp)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4223 求连续子序列和的最小绝对值,水题. #include <iostream> #inclu ...

  4. android adb devices offline的解决办法

    在做Android开发时经常出现android adb devices offline,解决办法如下: 1 重启adb服务 adb kill-server adb start-server linux ...

  5. 腾讯天猫经常出现这些低级的bug!

    对于程序员来说,bug很讨厌.每天重复着写代码.找bug.修改bug的动作.按理说互联网巨头的产品,bug应该比较少.但是实际上,无论是用百度.天猫.谷歌等产品,经常都会出现这些低级的bug,让人很火 ...

  6. Wannafly交流赛1_B_硬币【数学】

    Wannafly交流赛1_B_硬币[数学] 链接:https://www.nowcoder.com/acm/contest/69/B 来源:牛客网 题目描述 蜥蜴的生日快到了,就在这个月底! 今年,蜥 ...

  7. SQL char Nvarchar 详解

    Nvarchar :  可变长度的 , Unicode 编码.  长度 1-4000,  1个汉子 或者 字符 都是 2个字节. 支持多语言, 配合 大写 N 可以防止出现乱码. char:   固定 ...

  8. PHP-FPM 慢执行日志、网站隔离配置

    慢执行日志 1.配置文件下打开慢执行日志 vim /usr/local/php/etc/php-fpm.conf # 慢执行日志路径 slowlog = /path/to/slow.log # 设置超 ...

  9. 2018-2019-2 20165114《网络对抗技术》Exp2 后门原理与实践

    目录 一.实验准备 二.实验内容 三.基础问题回答 四.实验过程及步骤 五.实验总结与体会 六.实验中遇到的问题与错误. 一.实验准备 1.后门概念 后门就是不经过正常认证流程而访问系统的通道. 哪里 ...

  10. 六款常见的Linux操作系统推荐

    家常常可能因为工作或学习的需要,要使用个操作系统(比如Windows和Linux).大家对Windwos支持的文件系统可能比较熟悉,而对Linux操作系统所支持的文件系统也许比较陌生.下面小编为大家推 ...