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. Oracle 11g修改字符集AL32UTF8为ZHS16GBK

    oracle11g更改字符集AL32UTF8为ZHS16GBK当初安装oracle的时候选择的默认安装,结果字符集不是以前经常用的16GBK,要改字符集,从网上找到了方法并试了一下,果然好用! 具体如 ...

  2. pytho创建二维码简单版

    pytho创建二维码简单版 import qrcode aa = qrcode.make("https://github.com/phygerr/") aa.save('C:\Us ...

  3. 9.Query on Embedded/Nested Documents-官方文档摘录

    1.插入案例 db.inventory.insertMany( [ { item: "journal", qty: 25, size: { h: 14, w: 21, uom: & ...

  4. 48dp rhythm

  5. centos Docker安装前升级内核3.10的方法

    首先我虚拟机系统都是Centos 6.5 .ESXI ,后安装devel .ESXI 后来 .ESXI 我所操作的都是虚拟机,但是在真实机上面如何我就不清楚了~~ 大家一定要记得安装步骤,,,不然就是 ...

  6. 访问url

    你可以通过 args 属性来访问 URL 中提交的参数 ( ?key=value ): searchword = request.args.get('q', '') from flask import ...

  7. Django之查询总结

    models.Book.objects.filter(**kwargs): querySet [obj1,obj2]models.Book.objects.filter(**kwargs).value ...

  8. 转:Oracle中的日期和字符串互相转换

    TO_DATE格式(以时间:2007-11-02   13:45:25为例)          Year:             yy two digits 两位年                显 ...

  9. oracle procedure简单的将临时表的数据插入或更新到目标表

    CREATE OR REPLACE PROCEDURE DEAL_SYNC_SCH_CUSTPHONE_NEW AS CURSOR C_CURU IS SELECT * FROM CBS_COS.SC ...

  10. Levenshtein距离

    Levenshtein Distance,又称Edit Distance,在自然语言处理中有着广泛的应用.Levenshtein  Distance 指的是两个字符串之间,由一个转换成另一个所需的最少 ...