标签:母函数
4 10 20
5 42 627
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int M = 1e4 * 2;
typedef long long ll;
ll a[M],b[M];
/********/
/*
* 母函数,a数组是维护当前能组成的数的方法数,b数组为中间量;
* 母函数其实就是把组合加法于幂指数的乘法法则联合在一起
* 这相当于暴力查找符合题意的方法种数,取于不取的问题,取几个的问题;
*/
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i = 0; i <= n; i++)
{
a[i] = 1;
b[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) //接下来序列的指数,因为指数是以i递增的;
{
b[k + j] += a[j];
}
}
for(int j = 0; j <= n; j++) //更新序列;
{
a[j] = b[j];
b[j] = 0;
}
}
printf("%I64d\n",a[n]);
}
return 0;
}
Ignatius and the Princess III(母函数一种技巧性的暴力)
标签:母函数
原文地址:http://blog.csdn.net/zsgg_acm/article/details/38960649