题意

给出$n$,问用$1$到$n$的数字问能构成$n$的方案数

思路

生成函数基础题,$x^{n}$的系数即答案。

代码

#include <bits/stdc++.h>
#define DBG(x) cerr << #x << " = " << x << endl; using namespace std; const int N = 120 + 5; int n, c[2][N]; int main() {
while(~scanf("%d", &n)) {
for(int i = 0; i <= n; i++) c[1][i] = 1, c[0][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) c[i & 1][k + j] += c[1 - (i & 1)][j];
}
for(int j = 0; j <= n; j++) c[1 - (i & 1)][j] = 0;
}
printf("%d\n", c[n & 1][n]);
}
return 0;
}

  

HDU-1028 Ignatius and the Princess III(生成函数)的更多相关文章

  1. HDU 1028 Ignatius and the Princess III (生成函数/母函数)

    题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...

  2. hdu 1028 Ignatius and the Princess III 简单dp

    题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...

  3. HDU 1028 Ignatius and the Princess III 整数的划分问题(打表或者记忆化搜索)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1028 Ignatius and the Princess III Time Limit: 2000/1 ...

  4. hdu 1028 Ignatius and the Princess III(DP)

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

  5. HDU 1028 Ignatius and the Princess III (母函数或者dp,找规律,)

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

  6. hdu 1028 Ignatius and the Princess III 母函数

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

  7. hdu 1028 Ignatius and the Princess III (n的划分)

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

  8. HDU 1028 Ignatius and the Princess III (递归,dp)

    以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802  Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...

  9. HDU 1028 Ignatius and the Princess III (动态规划)

    题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...

  10. hdu 1028 Ignatius and the Princess III【生成函数】

    老是想着化简,实际上O(n^3)就行了-- 写成生成函数是\( \prod_{i=1}^{n}(1+x^i+2^{2i}+...+x^{ \left \lfloor \frac{n}{i} \righ ...

随机推荐

  1. Scrapy框架-Spider

    目录 1. Spider 2.Scrapy源代码 2.1. Scrapy主要属性和方法 3.parse()方法的工作机制 1. Spider Spider类定义了如何爬取某个(或某些)网站.包括了爬取 ...

  2. Mysql语句删除主键的自增

    ALTER TABLE 表名MODIFY COLUMN 字段名 int(2) NOT NULL FIRST ;

  3. 企业移动化?AppCan教你正确的打开方式

    七分选型.三分软件.的确,在过去的企业移动化进程中,由于选型失败导致信息系统实施失败的案例屡见不鲜.而在当今的移动互连和大数据时代,移动化已经是企业必然的选择. 那么,什么是企业移动化呢?怎样才是企业 ...

  4. [LeetCode] 17. 电话号码的字母组合

    题目描述:https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/ 题目描述: 给定一个仅包含数字 2-9 的字符 ...

  5. 闲谈2-sat问题

    问题简介 在计算机科学中,布尔可满足性问题(有时称为命题可满足性问题,缩写为SATISFIABILITY或SAT)是确定是否存在满足给定布尔公式的解释的问题.换句话说,它询问给定布尔公式的变量是否可以 ...

  6. typeScript面对对象篇二

    接口 接触过面向对象的后端语言的应该对接口很熟悉,只接触过前端的对接口会有点陌生,在维基百科中对OOP中接口的定义是这样的: 在面向对象的语言中,术语interface经常被用来定义一个不包含数据和逻 ...

  7. 转载:教你分分钟搞定Docker私有仓库Registry

    一.什么是Docker私有仓库Registry 官方的Docker hub是一个用于管理公共镜像的好地方,我们可以在上面找到我们想要的镜像,也可以把我们自己的镜像推送上去.但是,有时候我们的服务器无法 ...

  8. 使用axios 的post请求下载文件,

    axios({ method: 'post', data: param, responseType:'blob', url: _urls + '/Downloaddata' }).then(data= ...

  9. Python----简单线性回归

    简单线性回归 1.研究一个自变量(X)和一个因变量(y)的关系   简单线性回归模型定义:y=β0+β1x+ε 简单线性回归方程:E(y)=β0+β1x 其中: β0为回归线的截距 β1为回归线的斜率 ...

  10. Centos6.5 pppoe-server

    [root@localhost network-scripts]# rpm -q rp-pppoepackage rp-pppoe is not installed ----------------- ...