(Full backpack large number) Dollar Dayz (POJ 3181)

Source: Internet
Author: User
Tags dayz

http://poj.org/problem?id=3181

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 fo R Tools on sale with a cost of $ $K (1 <= K <=).

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 look at the full backpack, set up a template, very sorry WA, think about, unclear so, searched the next puzzle, actually said is because the result is too big, look at the data seems to be like this, is said to be two digits can be saved, the result is written submitted, decisive AC
#include <iostream>#include<queue>#include<cmath>#include<cstdio>#include<cstring>#include<cstdlib>#include<stack>#include<vector>#include<algorithm>using namespacestd;#defineN 2100#defineMet (A, B) (Memset (A,b,sizeof (a)))typedefLong LongLL; LL dp[n][2];intMain () {intN, M;  while(SCANF ("%d%d", &n, &m)! =EOF) {        intI, J; Met (DP,0); dp[0][0] =1;  for(i=1; i<=m; i++)         for(j=i; j<=n; J + +) {dp[j][0] + = dp[j-i][0]; dp[j][1] + = dp[j-i][1]; dp[j][1] + = dp[j][0]/1000000000000000; dp[j][0] %=1000000000000000; }        if(dp[n][1]==0) printf ("%i64d\n", dp[n][0]); Else{printf ("%i64d%015i64d\n", dp[n][1], dp[n][0]); }    }    return 0;}

Reference http://www.cnblogs.com/kuangbin/archive/2012/09/20/2695165.html

(Full backpack large number) Dollar Dayz (POJ 3181)

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.