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. Java 运行环境介绍

    Java 语言特点: 跨平台性: 一次编译,到处运行.即不受操作系统限制,编译一次,可以在多个平台运行.而这个优势得益于 JVM(Java Virtual Machine, 即Java 虚拟机). 两 ...

  2. Pandas 如何去除、取消已经设置好的索引

    Outline 今天处理数据时遇到一个问题: 因为业务需要,我对 df 进行了建立索引. 具体如下: 下面走的是默认索引 给其设置索引: 取消索引 业务需求,我要取消掉上面设置的索引: So,之前设置 ...

  3. python线程池应用场景-爬虫

    import requests from bs4 import BeautifulSoup from concurrent.futures import ThreadPoolExecutor, Pro ...

  4. Python高级教程-切片

    Python中的切片 取一个list或tuple的部分元素是非常常见的操作.比如,一个list如下: >>> L = ['A','B','C','D'] 对经常取指定索引范围的操作, ...

  5. Android学习十二---在android上实现图像匹配

    一.效果图及功能描述 效果图 点击ShowImg后 点击match,然后点击showmatch,可以不断点击showmatch. 主要功能描述:显示在SD卡上已经存在的图片test.jpg,根据图片在 ...

  6. java 多线程 day05 线程范围内的数据共享

    import java.util.HashMap;import java.util.Map;import java.util.Random;/** * Created by chengtao on 1 ...

  7. webdriver的API

    基本API 1.页面刷新    driver.fresh() 2.页面切换   driver.back().  driver.forward() 3.设置窗口大小    driver.set_wind ...

  8. 查看虚拟机操作系统、cpu核数、内存命令

    1.查看操作系统 在终端中执行下列指令:cat/etc/issue可以查看当前正在运行的 Ubuntu 的版本号.其输出结果类似下面的内容:Ubuntu 10.04 LTS \n \l方法二:使用 l ...

  9. BCH码

    http://baike.baidu.com/link?url=CfLtm9DigwWdup-9VJP99RG65NgaVOXfrnjT61ogP7au0QOrlypq72k67B0s1Ey-Q1yD ...

  10. 查询前几条记录 top limit

    SQL Server 数据库中的Top关键字可实现查询数据库表中的前几条数据,但是需要注意的是,Top关键字只能在SQL Server数据库中可以使用,而在MySQL数据库中就要使用具有同样功能的LI ...