poj3181 Dollar Dayz (dp+ large number)

Source: Internet
Author: User
Tags sca dayz

Dollar Dayz crawling in process ... crawling failedTime limit:MS Memory Limit:65536KB 64bit IO Format:%I 64D &%i64u SubmitStatus Practice POJ 3181Appoint Description:System Crawler (2016-05-27)

Description

Farmer John goes to Dollar days at the Cow Store and discovers a unlimited number of tools on sale. During his first visit, the tools is selling variously for $, $, and $. Farmer John has exactly $ to spend. He can buy 5 tools at $1 tool at $ and a additional 1 tool at $. Of course, there is other combinations for a total of 5 different ways FJ can spend all he money on tools. Here they is:

        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 would compute the number of ways FJ can spend N dollars (1 <= n <=) at the Cow Store for OLS on sale with a cost of $ $K (1 <= K <= 100).

Input

A single line with the space-separated integers:n and K.

Output

A single, with a single integer, is the number of the unique ways FJ can spend.

Sample Input

5 3

Sample Output

5
A DP question but because the number is too big ... So I chose the Java ...

Where DP array storage consists of the number of current numbers

Import Java.math.*;import java.util.*;p ublic 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]);}}



poj3181 Dollar Dayz (dp+ large number)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.