关闭

poj3181 Dollar Dayz (DP+大数)

标签: poj3181poj 3181
3387人阅读 评论(0) 收藏 举报
分类:

Dollar Dayz
Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Appoint description:

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
一个DP题 不过由于数太大了。。。所以我选用的java...

其中dp数组存贮组成当前数的个数

import java.math.*;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sca =new Scanner(System.in);
		int k,n;
		while(sca.hasNext())
		{
			n=sca.nextInt();
			k=sca.nextInt();
			BigInteger dp []=new BigInteger[1005];
			for(int i=0;i<1005;i++)
				dp[i]=BigInteger.ZERO;
			dp[0]=BigInteger.ONE;
			for(int i=1;i<=k;i++){
				for(int j=0;j<=n;j++){
					if(j>=i&&dp[j-i]!=BigInteger.ZERO){
						dp[j]=dp[j].add(dp[j-i]);
					}
				}
			}
			System.out.println(dp[n]);
		}
		
	}
}



1
0
查看评论

poj3181 Dollar Dayz dp

题目链接:here 题目大意:         n 块钱 如何由  1-k 块钱组合起来的方法。。 分析:         完全背包。。但是注意高精度。。 代码: java: import ja...
  • liuqiyao_01
  • liuqiyao_01
  • 2013-05-15 07:11
  • 1764

Dollar Dayz(DP)

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 ar...
  • Techay
  • Techay
  • 2016-01-15 20:51
  • 149

POJ 3181 Dollar Dayz(完全背包+简单高精度加法)

POJ 3181 Dollar Dayz(完全背包+简单高精度加法) http://poj.org/problem?id=3181 题意:        给你K种硬币,每种硬币分别是1美元,2美元…K美元且可以无限使用,问你用上面K种...
  • u013480600
  • u013480600
  • 2014-10-26 15:21
  • 1064

POJ 3181 Dollar Dayz 01完全背包问题

01完全背包问题。 主要是求有多少种组合。二维dp做的人多了,这里使用一维dp就可以了。 一维的转换方程:dp[j] = dp[j-i] + dp[j];其中i代表重量,j代表当前背包容量。 意思就是dp[j-i] 代表j-i背包重量的时候最多的组合数,那么如果到了背包容量为j的时候,就是可以把...
  • kenden23
  • kenden23
  • 2014-08-29 11:13
  • 974

POJ 3181 Dollar Dayz

其实这道题就是简单的完全背包问题。从低到高推断出每种硬币的所有面额的解即可。当然,离线的话会慢一点。可以将问题需要求出的子问题全部求出来。下一个问题出现的时候,如果之前已经求解过则不必求解,否则在之前的基础上继续求解。原本觉得没什么好写的,关键是同样的方法用STL中的vector代替数组会超时!搞得...
  • u011915301
  • u011915301
  • 2015-02-07 20:17
  • 524

POJ3181 Dollar Dayz

原以为跟前面两题一样,结果WA了几次,想了好久猜想到高精度问题,如输入1000 100,就算用一个long long数组也会溢出,结果为负数。本弱现在对于大数问题还没怎么研究,于是看了一下其他大牛的博客题解,受益匪浅啊~~~特别推荐kuangbin的,详细,而且有一步一步推导,值得看看 kuang...
  • L954688947
  • L954688947
  • 2015-10-30 23:54
  • 288

POJ 3181 Dollar Dayz

Dollar Dayz Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:8242   Accepted: 3082 De...
  • albertluf
  • albertluf
  • 2018-01-28 10:42
  • 8

POJ3181:Dollar Dayz(完全背包)

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...
  • libin56842
  • libin56842
  • 2013-07-24 21:36
  • 3514

【POJ3181】【Dollar Dayz】

Dollar Dayz Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2275 Accepted: 934 D...
  • u013200703
  • u013200703
  • 2015-08-02 09:27
  • 292

poj3181 Dollar Dayz

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 ar...
  • Kirito_Acmer
  • Kirito_Acmer
  • 2015-06-30 10:21
  • 557
    个人资料
    • 访问:1426909次
    • 积分:21073
    • 等级:
    • 排名:第445名
    • 原创:602篇
    • 转载:18篇
    • 译文:0篇
    • 评论:376条
    你只管努力 其它交给时光

    点图片联系我


    唐唐女神

    点图片联系我

    访问统计
    Flag Counter
    博客专栏
    最新评论