hdu1398 Square Coins

#include <stdio.h>  
#define MAXN 302  

int main()  
{  
	int arr1[MAXN],arr2[MAXN];  
	int i,j,k,n;  
	while(scanf("%d",&n)&&n)  
	{  
		for(i=0;i<=n;++i)  
		{  
			arr1[i]=1;  
			arr2[i]=0;  
		}  
		for (i=2;i<=17;++i)  
		{  
			for(j=0;j<=n;++j)  
				for (k=0;k+j<=n;k+=i*i)  
				{  
					arr2[k+j]+=arr1[j];  
				}  
				for (j=0;j<=n;++j)  
				{  
					arr1[j]=arr2[j];  
					arr2[j]=0;  
				}  
		}  
		printf("%d\n",arr1[n]);  
	}  
	return 0;  
}  

你可能感兴趣的:(hdu1398 Square Coins)