hdu1398母函数

#include<iostream>
using namespace std;

int X[18],c1[301],c2[301];

int main()
{
	int i,j,num,sum;
	for(i=1;i<=17;i++)	X[i]=500;
//	printf("!!!!!!!!\n");
	while(scanf("%d",&sum),sum)
	{
		
		memset(c1,0,sizeof(c1));memset(c2,0,sizeof(c2));
		for(i=0;i<=300;i++)	c1[i]=1;
		
		for(i=2;i<=17;i++)
		{
			for(j=0;j<=sum;j++)
			{
				if(c1[j])
				for(num=0;num<=X[i];num++)
				{
					if(num*i*i+j<=sum)	c2[num*i*i+j]+=c1[j];
					else	break;
				}
			}
			
			for(j=0;j<=sum;j++)
			{
				c1[j]=c2[j];
				c2[j]=0;
			}
		}
		
		printf("%d\n",c1[sum]);
		
	}
	return 0;
}


你可能感兴趣的:(c)