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)