题意

给出$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. Linux Mint如何添加windows分享的网络打印机?

    1.安装samba sudo apt-get install samba 2.找到系统打印机选项 通过 Menu-->>控制中心-->>系统管理找到 Printers选项,双击 ...

  2. docker 数据卷和docker数据卷容器以及数据卷的备份和还原

    一:数据卷 1.什么是数据卷 数据卷是通过特殊设计的目录,可以绕过联合文件系统,为一个或者多个容器提供服务,数据卷是在docker宿主机当中,数据卷可以是文件也可以是文件夹. 2.特点 1.数据卷在容 ...

  3. Linux:Day18(下) Bind9

    子域授权:每个域的名称服务器,都是通过其上级名称服务器在解析库中进行授权. 类似根域授权tld: .com IN NS ns1.com. .com IN NS ns1.com. ns1.com IN ...

  4. ios之库Protobuf的使用

    https://blog.csdn.net/dangbai01_/article/details/81099001 (1)Protobuf是什么? Protobuf 即 google protocol ...

  5. visual studio中各文件的输出路径

    dll或exe输出路径一般在 配置属性->链接器->常规->输出文件 中 若该路径与 配置属性->常规 中的输出目录+目标文件名+目标文件扩展名不一致,可能会有提示,建议保持一 ...

  6. 免费高端出辕营,横空出世惊鬼神 Excel插件:ExcelPower_Helper 0.41初出茅庐

    免费高端出辕营,横空出世惊鬼神 Excel插件:ExcelPower_Helper 0.41初出茅庐        隐鹤 倾心开发 2019.4.1 1.   引言 经过前后大约零零散散的一年的开发, ...

  7. flutter 本地存储 (shared_preferences)

    Flutter本地存储 和Android.Ios类似,Flutter也支持Preferences(Shared Preferences and NSUserDefaults) .文件.和Sqlite3 ...

  8. [转帖]Qemu 简述

    Qemu 简述 记得KVM 就是 底层用的qemu https://www.cnblogs.com/bakari/p/7858029.html 本文首发于我的公众号 Linux云计算网络(id: cl ...

  9. WebSocket原理

    一 . WebSocket原理 1.1.背景 WebSocket 是基于Http 协议的改进,Http 为无状态协议,基于短连接,需要频繁的发起请求,第二 Http 只能客户端发起请求,服务端无法主动 ...

  10. Python——SQL——将查询的数据列表化

    sql = 'select paihao from yang1.cailiaopai' data = datebase.shujuku.sj_select(sql) #将获得的数据进行列表化 data ...