//MiYu原创, 转帖请注明 : 转载自 ______________白白の屋
题目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=1398
也是一道基础的 母函数题目 , 详细可以参照 母函数 ( Generating function ) 详解
代码如下 :
题目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=1398
也是一道基础的 母函数题目 , 详细可以参照 母函数 ( Generating function ) 详解
代码如下 :
//MiYu原创, 转帖请注明 : 转载自 ______________白白の屋
#include <iostream>
using namespace std;
int num1[11111];
int num2[11111];
int main ()
{
int N;
while ( cin >> N , N )
{
for ( int i = 0 ; i <= N; ++ i )
{
num1[i] = 1;
num2[i] = 0;
}
for ( int i = 2; i <= 17; ++ i )
{
for ( int j = 0;j <= N; ++ j )
{
for ( int k = 0; k + j <= N; k += i * i )
{
num2[j + k] += num1[j];
}
}
for ( int j = 0; j <= N; ++ j )
{
num1[j] = num2[j];
num2[j] = 0;
}
}
cout << num1[N] << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int num1[11111];
int num2[11111];
int main ()
{
int N;
while ( cin >> N , N )
{
for ( int i = 0 ; i <= N; ++ i )
{
num1[i] = 1;
num2[i] = 0;
}
for ( int i = 2; i <= 17; ++ i )
{
for ( int j = 0;j <= N; ++ j )
{
for ( int k = 0; k + j <= N; k += i * i )
{
num2[j + k] += num1[j];
}
}
for ( int j = 0; j <= N; ++ j )
{
num1[j] = num2[j];
num2[j] = 0;
}
}
cout << num1[N] << endl;
}
return 0;
}