bzoj1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店
Description
Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are selling variously for $1, $2, and $3. Farmer John has exactly $5 to spend. He can buy 5 tools at $1 each or 1 tool at $3 and an additional 1 tool at $2. Of course, there are other combinations for a total of 5 different ways FJ can spend all his money on tools. Here they are: 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 will compute the number of ways FJ can spend N dollars (1 <= N <= 1000) at The Cow Store for tools on sale with a cost of $1..$K (1 <= K <= 100).
Input
A single line with two space-separated integers: N and K.
Output
A single line with a single integer that is the number of unique ways FJ can spend his money.
Sample Input
Sample Output
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 int max(int &a,int &b){return a>b?a:b;} 6 int n,k; 7 struct bignum{ 8 int a[100],len; 9 bignum(){memset(a,0,sizeof(a));len=0;} 10 void print(){ 11 for(int i=len;i;--i) printf("%d",a[i]); 12 } 13 bignum operator + (const bignum &tmp) const{ 14 bignum c; int x=0; 15 c.len=max(len,tmp.len); 16 for(int i=1;i<=c.len;++i){ 17 c.a[i]=a[i]+tmp.a[i]+x; 18 x=c.a[i]/10; c.a[i]%=10; 19 }for(;x;x/=10) c.a[++c.len]=x%10; 20 return c; 21 } 22 }f[1002]; 23 int main(){ 24 scanf("%d%d",&n,&k); 25 f[0].a[f[0].len=1]=1; 26 for(int i=1;i<=k;++i) 27 for(int j=i;j<=n;++j) 28 f[j]=f[j]+f[j-i]; 29 f[n].print(); 30 return 0; 31 }