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. Response 和 Request

    1. request 对象和 response 对象均由服务器创建. 2. 服务器处理请求的流程: 服务器每次收到请求时, 都会为这个请求开辟一个新的线程; 服务器会把客户端的请求数据封装到 requ ...

  2. XPath 快速入门

    XPath 是一门在 xml 文档中查找信息的语言. XPath 使用路径表达式来选取 xml 文档中的节点或者节点集合. 路径表达式由元素和属性组成. 语法介绍 // 示例: // xml 文档 & ...

  3. 深入理解Mysql索与事务隔离级别

    1. 概述 1.1 定义 锁是计算机协调多个进程或线程并发访问某一资源的机制. 在数据库中,除了传统的计算资源(如CPU.RAM.I/O等)的争用以外,数据也是一种供需要用户共享的资源.如何保证数据并 ...

  4. .net ASPxTreeList 使用手记

    ASPxTreeList在使用ASPxGridViewExporter控件做导出时,如果指定文件名是中文时会乱码可以用以下方法解决: grvExporter为ASPxGridViewExporter控 ...

  5. (2.2)学习笔记之mysql基础操作(登录及账户权限设置)

    本系列学习笔记主要讲如下几个方面: 本文笔记[三:mysql登录][四:账户权限设置][五:mysql数据库安全配置] 三.mysql登录 常用登录方式如下: 四.账户权限设置 (4.1)查看用户表, ...

  6. PAT 1071 Speech Patterns[一般]

    1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For exam ...

  7. js基本

    BOM 浏览器对象模型 DOM 文档对象模型 js主要是来操作DOM和BOM,用的事件驱动方式,通过事件去执行相应函数 如何加载:在html当中有写链接,然后加载的时候会把js函数,数据全取出来,然后 ...

  8. php 获取数组中的key值

    <?php $arr = array( 'book' => 1, 'data' => 'data', 'music' => 'music', 'img' => 'img' ...

  9. pycharm断点调试

    step over 执行下一步 蓝色高亮的那一行表示准备执行的代码

  10. Linux统计文件数目

    统计当前目录下文件数目 $ find . -type f | wc -l 统计文件行数 $ wc -l filename 仅统计内容为pattern的行(只有pattern) $ grep -w &q ...