题意

给出$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;
}

  

转载于:https://www.cnblogs.com/DuskOB/p/10604288.html

HDU-1028 Ignatius and the Princess III(生成函数)相关推荐

  1. hdu 1398 Square Coins/hdu 1028 Ignatius and the Princess III

    两道母函数的模板题: http://acm.hdu.edu.cn/showproblem.php?pid=1398 View Code #include<iostream>#include ...

  2. HDU 1028 Ignatius and the Princess III

    //强行递推. xx[i][j]表示i数中第j个开头的组合种类. /* 最终结果[i]为 sum of(xx[i][j])  (j from 1  to i); xx[i][j]=sum of (xx ...

  3. hdu 1028 Ignatius and the Princess III 母函数入门

    传送门 文章目录 题意: 思路: 题意: 给你一个数nnn,问你有多少种方案用1−n1-n1−n的数能组成nnn,数的使用次数无限制. n≤120n\le120n≤120 思路: 考虑构造母函数. 对 ...

  4. HUOJ 1028 Ignatius and the Princess III(完全背包计数问题)

    为了字节跳动的面试,复习一波算法 题目描述:输入一个n,输出n的所有组成方案,例如: n=4,有 4 = 4; 4 = 3 + 1; 4 = 2 + 2; 4 = 2 + 1 + 1; 4 = 1 + ...

  5. LETTers比赛第三场 --1002 Ignatius and the Princess III解题报告

    提交人:侯建鹏 提交日期:2012/4/16 1002 Ignatius and the Princess III 解题思路(一):动态规划 先设置int p[N][N]; Dp 方程为:p[i][j ...

  6. HDU 1028 HDU Ignatius and the Princess III

    简单的钱币兑换问题,就是钱的种类多了一点,完全背包. #include<cstdio> #include<cstring> int main () {int i,j,dp[12 ...

  7. HDU 1026 Ignatius and the Princess I(BFS)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1026 在这博客学的 ttp://www.wutianqi.com/?p=2354 感觉看了这个之后收获 ...

  8. HDU - 1029 Ignatius and the Princess IV

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=1029 题目大意 给你n(n为奇数, n < 1e6)个数,让你找到个数 >=( ...

  9. Hdu 1029 Ignatius and the Princess IV

    思路:普通的cin会超时 方法很妙 1 #include<iostream> 2 #include<algorithm> 3 #include<string> 4 ...

最新文章

  1. easyexcel写入数据为空_如何解决Redis缓存和MySQL数据一致性的问题?
  2. js 乘法除法精度问题
  3. 【数据结构】用java实现不同的七种排序算法和性能比较
  4. uni-app中view组件的基本使用
  5. cube云原生机器学习平台-架构(五)
  6. 我用wget下载CentOS镜像文件
  7. ISP之色差增益抑制(Chroma Gain Suppression)
  8. 软件测试--IEEE829标准
  9. MPLAB PICKIT3、MPLAB SIM调试
  10. 「第五章」点击劫持(ClickJacking)
  11. uniapp之安卓使用高德地图
  12. Redis笔记(Linux部署redis过程)
  13. 嵌入式Linux是学驱动还是应用,嵌入式LINUX应该学什么?做驱动还是做应用
  14. 基于MATLAB的小波阈值去噪
  15. c盘是不是越大越好_Windows系统磁盘分区,C盘划分多大最合适?不是越大越好!...
  16. 全球定位系统和惯性系统在高速公路上的高精密定位
  17. 我的2017年广州IT公司从入职到离职
  18. 数据挖掘与机器学习:Apripori算法
  19. Navicat Premium 16 for Mac 最新版
  20. fft2 二维快速傅里叶变换(Matlab)

热门文章

  1. Go语言 科学计算库 Gonum 学习1
  2. oracle10g的silent,Linux 静默(Silent) 安装Oracle 10g
  3. 计算机是管理信息系统的必要条件吗,管理信息系统复习题(有答案)..doc
  4. 最新 springBoot整合shiro(10分钟教程)
  5. libevent源码学习-----event_base事件循环
  6. 作为资深的无人机从业者,卡尔曼滤波你不能不知道 通俗易懂的来说卡尔曼滤波
  7. 2019牛客暑期多校训练营(第六场)E - Androgynos (构建自补图)
  8. 牛客练习赛25 B-最长区间
  9. POJ 1088(滑雪)
  10. 解决安装pytorch慢的方法(pip安装)