poj3181 Dollar Dayz

Source: Internet
Author: User
Tags dayz

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

Test instructions: Give you two number n,k, let you use 1 to k this k number represents n, ask there are several methods, the essence is the splitting of integers. Because the final result is larger than a long long, so with two long long concatenated, set two array a[][],b[][] to indicate that there is not more than a long long part and more than a long long.

where a[n][m] means n with some number of split, where the largest number of the program number is not more than M, drawing can be seen when n<m, A[i][j]=a[i][i]; when N>=m, a[i][j]= (a[i][j-1]+a[i-j][j))%inf; Initialize the time to make a[0][i]=1, because a[2][2]=a[0][2]+a[2][1];

6
5 + 1
4 + 2, 4 + 1 + 1
3 + 3, 3 + 2 + 1, 3 + 1 + 1 + 1
2 + 2 + 2, 2 + 2 + 1 + 1, 2 + 1 + 1 + 1 + 1
1 + 1 + 1 + 1 + 1 + 1

#include <stdio.h>
#include <string.h>
#define LL Long Long
ll a[1006][106],b[1006][106];
ll INF;
int main ()
{
int n,m,i,j;
inf=1;
for (i=1;i<=18;i++) {
inf*=10;
}
while (scanf ("%d%d", &n,&m)!=eof)
{
memset (A,0,sizeof (a));
Memset (b,0,sizeof (b));
for (i=1;i<=m;i++) {
A[0][i]=1;
}
for (i=1;i<=n;i++) {
A[i][1]=1;
}
for (j=1;j<=m;j++) {
A[1][j]=1;
}

for (j=2;j<=m;j++) {
for (i=2;i<=n;i++) {
if (i<j) {
A[i][j]=a[i][i];
B[i][j]=b[i][i];
}
else{
A[i][j]= (A[i][j-1]+a[i-j][j])%inf;
b[i][j]=b[i][j-1]+b[i-j][j]+ (A[i][j-1]+a[i-j][j])/inf;
}
printf ("%d%d%d\n", i,j,a[i][j]);
}
}
if (B[n][m])
printf ("%lld", B[n][m]);
printf ("%lld\n", A[n][m]);
}
return 0;
}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

poj3181 Dollar Dayz

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.