题意

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

思路

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

代码

  1. #include <bits/stdc++.h>
  2. #define DBG(x) cerr << #x << " = " << x << endl;
  3.  
  4. using namespace std;
  5.  
  6. const int N = 120 + 5;
  7.  
  8. int n, c[2][N];
  9.  
  10. int main() {
  11. while(~scanf("%d", &n)) {
  12. for(int i = 0; i <= n; i++) c[1][i] = 1, c[0][i] = 0;
  13. for(int i = 2; i <= n; i++) {
  14. for(int j = 0; j <= n; j++) {
  15. for(int k = 0; k + j <= n; k += i) c[i & 1][k + j] += c[1 - (i & 1)][j];
  16. }
  17. for(int j = 0; j <= n; j++) c[1 - (i & 1)][j] = 0;
  18. }
  19. printf("%d\n", c[n & 1][n]);
  20. }
  21. return 0;
  22. }

  

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. react-router(v4)

    概要 开发单页应用, 首先绕不开的内容就是路由, react router v4 版本是最新的版本. 和之前的版本相比, 成熟了很多, 也简单了很多, 使用起来更加方便. 核心 component r ...

  2. RESTful学习及应用

    原文转自前端路上,转载请注明出处:http://refined-x.com/2017/09/22/RESTful学习及应用/ RESTful是什么 RESTful是一种API架构,符合REST设计原则 ...

  3. 分布式存储ceph——(3)ceph常用命令

    1.查看ceph集群配置信息 1 ceph daemon /var/run/ceph/ceph-mon.$(hostname -s).asok config show   2.在部署节点修改了ceph ...

  4. iOS 友盟错误分析-2019

    友盟的错误分析越来越人性化了 前提集成了友盟统计,并打包的时候保留了.dSYM文件 先看看效果 可以看到bug显而易见的被发现了!那个文件夹,那一行代码 那么怎么才能这样呢 首先加入符号表,就是.dS ...

  5. FreeMarker 入门

    目录 FreeMarker是什么 为什么要学习FreeMarker FreeMarker相关站点

  6. jmeter学习记录--10--二次开发环境搭建

    JMeter源码集成到Eclipse.JMeter二次开发(1)-eclipse环境配置及源码编译 ,根据此文章记录将jmeter源码集成到myecplise 第一步:下载jmeter源码http:/ ...

  7. mysql 增删改查基础操作的语法

    前提,数据表的结构是这样的 一.插入内容到数据表 INSERT INTO `数据库名`.`数据表名` (`t_title`, `t_con`) VALUES ('标题1', '内容1'); 或这样 I ...

  8. java基础问题巩固(1)

    你对java垃圾回收了解吗?什么时候需要使用? 答: 垃圾回收器的作用是查找和回收(清理)无用的对象,从而让jvm更 有效的使用内存.但是运行因为垃圾回收本身会有开销,过于频繁的使用会导致性能下降.比 ...

  9. Windows平台安装TensorFlow Q&A

    ·本文讲的是Windows平台使用原生pip进行TensorFlow(CPU版本)安装的注意事项及常见问题解决方法 ·这是TensorFlow官网的安装介绍:在 Windows 上安装 TensorF ...

  10. Bootstrap 模态框(Modal)插件id冲突

    <!DOCTYPE html><html><head>    <meta charset="utf-8">     <titl ...