Dollar dayztime limit:1000msmemory limit:65536kb64-bit integer IO format:%lldJava class Name:MainPrevsubmitstatus Statistics discuss Next
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
Source Usaco 2006 January Silver
Idea: An integer division problem of a Laosheng long conversation
Note: is a large number long long but!! is a group of data that is not multiple groups of!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!
#include <bits/stdc++.h>using namespace Std;const long long Inf=1e15;long long Num[100];long long dp[1010][110][10 ];void Add (int a,int b,int c,int D)//15 digits per bit {long long mx=0; for (int i=0; i<3; i++) {Long long z=dp[a][b][i]+dp[c][d][i]+mx; Dp[a][b][i]=z%inf; Mx=z/inf; }}void print (int a,int b)//{int t=0; for (int i=0; i<3; i++) {num[i]=dp[a][b][i]; printf ("%d%d%d\n", a,b,i,dp[a][b][i]); if (dp[a][b][i]!=0) t=i; } for (int i=t; i>=0; i--) {if (i!=t) printf ("%015lld", Num[i]); else printf ("%lld", Num[i]); } printf ("\ n");} int main () {int n,k; while (~SCANF ("%d%d", &n,&k)) {memset (dp,0,sizeof (DP)); printf ("*****\n"); for (int i=1; i<=n+1; i++) {dp[i][1][0]=1; int aaa=min (I,K); for (int j=2; j<=aaa; J + +) {for (int k=1; k<=j; k++) {if (i-k<k) Add (i,j,i-k,i-k); DP[I][J] = Dp[i][j] + dp[i-k][i-k]; else Add (i,j,i-k,k); DP[I][J] = Dp[i][j] + dp[i-k][k]; }}} int t=0; for (int i=0; i<3; i++) {num[i]=dp[n+1][k][i]; printf ("%d%d%d\n", a,b,i,dp[a][b][i]); if (dp[n+1][k][i]!=0) t=i; } for (int i=t; i>=0; i--) {if (i!=t) printf ("%015lld", Num[i]);//Complement 0 E LSE printf ("%LLD", Num[i]); } printf ("\ n"); }}
Dollar Dayz (large number DP fuck! Not multiple sets of data!! )