poj3181 Dollar Dayz (DP+大数)

Dollar Dayz

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

Submit
Status Practice POJ 3181

Appoint description:
System Crawler (2016-05-27)

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]);
		}

	}
}
时间: 2024-10-08 17:17:47

poj3181 Dollar Dayz (DP+大数)的相关文章

Dollar Dayz (大数dp fuck!不是多组数据!!)

Dollar Dayz Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on s

POJ3181 Dollar Dayz 【母函数】+【高精度】

Dollar Dayz Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4204   Accepted: 1635 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 sell

[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 selling variously for $1, $2, and $3. Farmer John has exactly $5 to spend. He can buy 5 tools at $1

poj 3181 Dollar Dayz DP

题意:给你一个n,还有k,求问有多少种数字组合,能够使得数字之和为n,这些数字的范围是1到k. 如,给你n=4, k=2.那么 1+1+1+1=4, 1+1+2=4,2+2=4,四种组合. 思路:完全背包,可以设d[i][j]代表从i个数字相加和为j的组合数. 那么,可以考虑把这些组合数分为,有数字i和没有数字i,那么没有数字i的组合数就为d[i-1][j],有数字i的组合数就为d[i][j-i](可以在这些组合里面加上1个i). 所以,转移方程可以写成d[i][j] = d[i-1][j] +

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

POJ 3181 Dollar Dayz(完全背包+简单高精度加法) http://poj.org/problem?id=3181 题意: 给你K种硬币,每种硬币分别是1美元,2美元-K美元且可以无限使用,问你用上面K种硬币构成n美元的话有多少种方法? 分析: 本题是一道明显的完全背包问题, 不过本题还可以换一种方法来看: 整数n由前K个自然数构造, 一共有多少种方法? (虽然本题要用到高精度加法, 但是很简单, 不要被吓到哦) 首先是DP部分: 令dp[i][j]==x 表示由前i种硬币构成j

[hdu 4933]Miaomiao&#39;s Function 数位DP+大数

Miaomiao's Function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 79    Accepted Submission(s): 18 Problem Description Firstly , Miaomiao define two functions f(x) , g(x): (K is the smallest

POJ3181——DP(找钱3)——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 selling variously for $1, $2, and $3. Farmer John has exactly $5 to spend. He can buy 5 tools at $1

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

题意:给出整数n和k,n代表拥有的钱数量,k代表有k种工具,其价钱分别为1~k.求n元能有多少种购买的方案. 思路:k最大有100,数量过大,要用大数.其他的基本和完全背包一样. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 const int B=1005, N=150; 7 int

Dollar Dayz poj3181

http://poj.org/problem?id=3181 这个题目一开始就能看出来是个dp问题,但是我并没有一开始就看出来是一个完全背包为题,只是想着根据以前的方法,这个问题应该是可以找到规律的,但是,还是被坑了,这还是一个大数问题! 首先我膜拜一下hankcs大神的: /////////////////////////////////////////////////////////// #include <iostream> using namespace std; unsigned l