题目:给你数n,问n可以有哪些组成方案(这些n的数字个数不超过n),母函数模板题

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int n;
int a[125], t[125];//a[i]表示x^i的系数,即凑成数i的方案数

int main() {
    while (1 == scanf("%d", &n)) {
        for (int i = 0; i <= n; ++i) {//初始化第一个表达式 (1+x+x^2+…+x^n),系数均为1
            a[i] = 1;
            t[i] = 0;
        }

        for (int i = 2; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                for (int k = 0; j + k <= n; k = k + i) {
                    t[j + k] += a[j];
                }

            }
            for (int j = 0; j <= n; j++) {
                a[j] = t[j];
                t[j] = 0;

            }

        }
        printf("%d\n", a[n]);
    }

    return 0;
}

HDU1028【母函数】的更多相关文章

  1. hdu1028(母函数+DP)

    题目信息:求分解整数n的个数q(n);能够母函数或者DP http://acm.hdu.edu.cn/showproblem.php?pid=1028 AC代码: /***************** ...

  2. hdu刷题2

    hdu1021 给n,看费波纳列数能否被3整除 算是找规律吧,以后碰到这种题就打打表找找规律吧 #include <stdio.h> int main(void) { int n; whi ...

  3. 【母函数】hdu1028 Ignatius and the Princess III

    大意是给你1个整数n,问你能拆成多少种正整数组合.比如4有5种: 4 = 4;  4 = 3 + 1;  4 = 2 + 2;  4 = 2 + 1 + 1;  4 = 1 + 1 + 1 + 1; ...

  4. ACM学习历程—HDU1028 Ignatius and the Princess III(递推 || 母函数)

    Description "Well, it seems the first problem is too easy. I will let you know how foolish you ...

  5. HDU1028 Ignatius and the Princess III 【母函数模板题】

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  6. acm之路--母函数 by小宇

    母函数又叫生成函数,原是数学上的一个名词,是组合数学中的一个重要理论. 生成函数是说,构造这么一个多项式函数g(x).使得x的n次方系数为f(n). 对于母函数,看到最多的是这样两句话: 1.&quo ...

  7. HDU 1398 Square Coins(母函数或dp)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  8. HDU-1028-Ignatius and the Princess III(母函数)

    链接: https://vjudge.net/problem/HDU-1028 题意: "Well, it seems the first problem is too easy. I wi ...

  9. hdu2082 找单词 (母函数)

    找单词 题意: 中文题,考虑是不是要写个英文题意..(可惜英语水平不够  囧rz)                (题于文末) 知识点: 母函数(生成函数): 生成函数有普通型生成函数和指数型生成函数 ...

随机推荐

  1. eclipse报错排解

    一.解决eclipse中git插件中的cannot open git-upload-pack问题 有时候在eclipse上使用插件egit向github或者osc上同步代码时,有时候会发现出现cann ...

  2. Android Service 基础

    启动方式 startService(Intent) 这种方式启动的Service可以在后台无限期的运行,与启动它的组件没有关系. bindService 绑定Service.它提供了一种类似C/S结构 ...

  3. Webpack的基本配置

    一.优化项目结构,创建相关的文件,项目结构如下:src文件夹存放相关js文件,index.html项目的首页面,dist文件夹是webpack 打包 目录. index.js内容为: alert('我 ...

  4. Sagit.Framework For IOS 开发框架入门教程5:消息弹窗STMsgBox

    前言: 昨天刚写了一篇IT连创业的文章:IT连创业系列:产品设计之答题模块,(欢迎大伙关注!) 感觉好久没写IOS的文章了,今天趁机,来补一篇,Sagit的教程. Sagit 开源地址:https:/ ...

  5. phpcms v9 搜索结果列表页时间显示1970问题解决方案

    对于喜欢用phpcms v9 的小伙伴来说,在调用时间时,总会出现时间1970这样的问题,对于这个问题,网上的说法很多,内容页时间显示通常不会问题,搜索结果页就不行了,通过总结,发现使用{format ...

  6. DOM4j的修改删除方式

    ?xml version="1.0" encoding="UTF-8"?> <contactList> <contact id=&quo ...

  7. html5 input type="color"边框伪类效果

    html5为input提供了新的类型:color <input type="color" value="#999" id="color" ...

  8. 【Nginx系列】Nginx虚拟主机的配置核日志管理

    Nginx配置段 #user nobody; worker_processes 1;// 有1个工作的子进程,可以自行修改,但太大无益,因为要争夺CPU,一般设置为 CPU数*核数 #error_lo ...

  9. 通过cmd窗口导入导出mysql数据库

    1.导入数据库 使用source命令 首先要在cmd窗口中连接数据库,然后再用source命令进行导入操作 mysql>use 数据库名 mysql>source d:/dbname.sq ...

  10. 福州大学W班-需求分析评分排名

    作业链接 https://edu.cnblogs.com/campus/fzu/FZUSoftwareEngineering1715W/homework/1019 作业要求 1.需求文档 1) 参考& ...