题意

给出$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. windows10+VS+CUDA+cuDNN+TensorFlow-gpu环境搭建(问题及解决)

    TensorFlow-gpu环境需要CUDA+cuDNN+python,CUDA又需要VS,所以,,,环境越来越大哈哈. 1.主要环境: Python 3.6 CUDA9.0 Cudann7.0 Te ...

  2. keil 中报错和警告提示解决办法

    1.warning: #1-D: last line of file ends without a newline 解决办法:在文件最后一行加入一个回车. 2.error: #134: expecte ...

  3. ztree 获取子节点所有父节点的name的拼接

    ztree 获取子节点所有父节点的name的拼接 //获取子节点,所有父节点的name的拼接字符串function getFilePath(treeObj){if(treeObj==null)retu ...

  4. VMware Workstation14 安装Ubuntu18.04

    1 下载Vmware Workstations14破解版 百度网盘链接:https://pan.baidu.com/s/12yVxoPCJUAmdts4SUdzndg 提取码:bs0g 2 下载Ubu ...

  5. 360大牛:全面解读PHP面试

    让大家了解基本面试流程和面试的核心要求以及意义是什么并理解PHP面试考点主要以基础为核心,说明PHP面试考察范围. 有需要联系:QQ:1844912514

  6. CodeForces 1151F Sonya and Informatics

    题目链接:http://codeforces.com/problemset/problem/1151/F 题目大意: 给定长度为 n 的 01 序列,可以对该序列操作 k 次,每次操作可以交换序列中任 ...

  7. parcel+vue入门

    一.parcel简单使用 npm install -D parcel-bundler npm init -y (-y表示yes,跳过项目初始化提问阶段,直接生成package.json 文件.) Pa ...

  8. Jetson TX1使用usb camera采集图像 (2)

    该方法只启动usb摄像头 import cv2 import numpy import matplotlib.pyplot as plot class Camera: cap = cv2.VideoC ...

  9. 台达wplsoft2.34指令表

    常用: LD 载入 A 接点 LDI 载入 B 接点 AND 串联 A 接点 ANI 串联 B 接点 OR 并联 A 接点 ORI 并联 B 接点 ANB 串联回路方块 ORB 并联回路方块 MPS ...

  10. 构建自定义docker镜像,上传至docker hub

    docker 优势 (外部参考) Docker 让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后 发布到任何流行的Linux机器上,便可以实现虚拟化.Docker改变了虚拟化的方 式,使 ...