BZOJ 1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店 (母函数,高精度)

1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店

Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 353  Solved: 190 [Submit][Status][Discuss]

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).

    约翰到奶牛商场里买工具.商场里有K(1≤K≤100).种工具,价格分别为1,2,…,K美元.约翰手里有N(1≤N≤1000)美元,必须花完.那他有多少种购买的组合呢?

Input

A single line with two space-separated integers: N and K.

    仅一行,输入N,K.

Output

A single line with a single integer that is the number of unique ways FJ can spend his money.

    不同的购买组合数.

Sample Input

5 3

Sample Output

5

思路:母函数裸题,还卡个高精度。。差评。。。

/* ***********************************************
Author :111qqz
Created Time :2016年04月14日 星期四 16时42分31秒
File Name :code/bzoj/1655.cpp
************************************************ */
 1#include <cstdio>
 2#include <cstring>
 3#include <iostream>
 4#include <algorithm>
 5#include <vector>
 6#include <queue>
 7#include <set>
 8#include <map>
 9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6const int N=1E4+7;
7const int MAXN =300;
8int n,m;
9int a[N][105],tmp[N][105];
1void add(int x,int y)
2{
3    for ( int i = 1 ; i <= 100 ; i++)
4	tmp[x][i]+=a[y][i];
1    for ( int i = 1 ; i <= 100 ; i++)
2    {
3	tmp[x][i+1]+=tmp[x][i]/10;
4	tmp[x][i]%=10;
5    }
}
1void tran( int x)
2{
3    for ( int i = 1 ; i <= 100 ; i++)
4    {
5	a[x][i] = tmp[x][i];
6	tmp[x][i] =  0;
7    }
8}
1int main()
2{
3	#ifndef  ONLINE_JUDGE 
4	freopen("code/in.txt","r",stdin);
5  #endif
1	scanf("%d %d",&n,&m);
2	ms(a,0);
3	m = min(m,n);
4	for ( int i = 0 ; i <= n ; i++)
5	{
6	    a[i][1] = 1;
7	    tmp[i][1] =  0 ;
8	}
 1	for ( int i = 2 ; i <= m ; i++)
 2	{
 3	    for ( int j = 0 ;j <= n ; j++)
 4	    {
 5		for ( int k = 0 ; k+j<= n ; k+=i)
 6		{
 7		    for ( int z = 1 ; z <= 40 ; z++)
 8		    {
 9			tmp[k+j][z] += a[j][z];
10		    }
1		}
2	    }
3//	    cout<<"aaa"<<endl;
 1	    for ( int j = 0 ; j <= n ; j++)
 2	    {
 3		for ( int z = 1 ; z <= 40 ; z++)
 4		{
 5		    tmp[j][z+1]+=tmp[j][z]/10;
 6		    tmp[j][z]%=10;
 7		}
 8	    }
 9	    for ( int j = 0 ; j <= n ; j++)
10	    {
11		for ( int z = 1 ; z <= 40 ; z++)
12		{
13		    a[j][z] = tmp[j][z];
14		    tmp[j][z]  = 0;
15		}
16	    }
17	}
1	int len = 100;
2	while (a[n][len]==0) len--;
3//	cout<<"len:"<<len<<endl;
4	for ( int i = len  ;i >0 ; i--) printf("%d",a[n][i]);
1  #ifndef ONLINE_JUDGE  
2  fclose(stdin);
3  #endif
4    return 0;
5}