//MiYu原创, 转帖请注明 : 转载自 ______________白白の屋
题目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=1028
标准的母函数题目 ,很基础, 可以直接使用模板, 不过敲代码也用不了多长时间,建议手打,加深记忆.
代码如下 :
题目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=1028
标准的母函数题目 ,很基础, 可以直接使用模板, 不过敲代码也用不了多长时间,建议手打,加深记忆.
代码如下 :
//MiYu原创, 转帖请注明 : 转载自 ______________白白の屋
#include <iostream>
using namespace std;
int num1[122];
int num2[122];
int main ()
{
int N;
while ( cin >> N )
{
for ( int i = 0 ; i <= N; ++ i )
{
num1[i] = 1;
num2[i] = 0;
}
for ( int i = 2; i <= N; ++ i )
{
for ( int j = 0;j <= N; ++ j )
{
for ( int k = 0; k + j <= N; k += 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[122];
int num2[122];
int main ()
{
int N;
while ( cin >> N )
{
for ( int i = 0 ; i <= N; ++ i )
{
num1[i] = 1;
num2[i] = 0;
}
for ( int i = 2; i <= N; ++ i )
{
for ( int j = 0;j <= N; ++ j )
{
for ( int k = 0; k + j <= N; k += 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;
}