首页 > 其他 > 详细

HDU 1028 Ignatius and the Princess III 母函数

时间:2014-08-07 12:31:29      阅读:326      评论:0      收藏:0      [点我收藏+]

其实这题是水题,DP随便搞一下就能求,但是第一次写母函数,所以找了道水题做好理解些~_~

 

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <string>
#include <iostream>
#include <map>
#include <cstdlib>
#include <list>
#include <set>
#include <queue>
#include <stack>

using namespace std;

typedef long long LL;
const int maxn = 125;
int c1[maxn],c2[maxn];

int main() {
    int n;
    while(scanf("%d",&n) == 1) {
        //用第一个多项式初始化
        for(int i = 0;i <= n;i++) {
            c1[i] = 1; c2[i] = 0;
        }
        //第i个多项式
        for(int i = 2;i <= n;i++) {
            //第i个多项式中的第j项
            for(int j = 0;j <= n;j += i) {
                //依次累加
                for(int k = 0;k + j <= n;k++) {
                    c2[k + j] += c1[k];
                }
            }
            memcpy(c1,c2,sizeof(c1));
            memset(c2,0,sizeof(c2));
        }
        printf("%d\n",c1[n]);
    }
    return 0;
}

  

 

HDU 1028 Ignatius and the Princess III 母函数,布布扣,bubuko.com

HDU 1028 Ignatius and the Princess III 母函数

原文:http://www.cnblogs.com/rolight/p/3896410.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!