HDU-1028 Ignatius and the Princess III(生成函数)
题意
给出$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(生成函数)的更多相关文章
- HDU 1028 Ignatius and the Princess III (生成函数/母函数)
题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...
- hdu 1028 Ignatius and the Princess III 简单dp
题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...
- 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 ...
- 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 ...
- 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 ...
- hdu 1028 Ignatius and the Princess III 母函数
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- 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 ...
- HDU 1028 Ignatius and the Princess III (递归,dp)
以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802 Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...
- HDU 1028 Ignatius and the Princess III (动态规划)
题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...
- 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 ...
随机推荐
- 周一04.3流程控制while循环
#循环就是重复做某件事 1.条件循环:while,语法如下 while 条件: # 循环体 # 如果条件为真,那么循环体则执行,执行完毕后再次循环,重新判断条件... # 如果条件为假,那么循环体不执 ...
- 周一02.4变量&垃圾回收机制
一.变量 1. 什么是变量 量:记录事物的某种状态,即事物典型的特征 变:事物的状态是可以发生变化的 2. 为何要用变量 是为了让计算机能够像人一样记录事物的状态 3. 如何用变量 (先定义后引用) ...
- 013_针对单个pid的cpu/内存/io的资源占用统计
#!/usr/bin/env python import sys import os import subprocess from decimal import Decimal from decima ...
- c++ primer plus 第二章 \n与endl在输出上的区别
在书上看到如下一段话: 一个差别是,endl确保程序继续运行前刷新输出(将其立即显示在屏幕上):而使用"\n"不能提供这样的保证,这意味着在有些系统中,有时可能在您 ...
- Elasticsearch 通关教程(四): 分布式工作原理
前言 通过前面章节的了解,我们已经知道 Elasticsearch 是一个实时的分布式搜索分析引擎,它能让你以一个之前从未有过的速度和规模,去探索你的数据.它被用作全文检索.结构化搜索.分析以及这三个 ...
- html中的meta标签是什么?有哪些属性?
meta标签介绍 meta标签是HTML语言head区域的一个辅助性标签,常用于定义页面的说明,关键字,最后修改的日期和其他的元数据.这些元数据将服务于浏览器,搜索引擎和其他网络服务. meta标签的 ...
- 'cordova' 不是内部或外部命令,也不是可运行的程序
问题: CMD 'cordova' 不是内部或外部命令,也不是可运行的程序: 解决:配置环境变量 1.找到npm的安装路径 :如C:\Users\AppData\Roaming\npm 2.环境 ...
- Idea在@Autowired注入时报错
Could not autowire. No beans of 'UserDao' type found 如图,是因为idea检测能力太强,一旦没有找到实现类就会报错,但是我试了,这里其实是注入进来了 ...
- 使用cURL尝试ElasticSearch
测试环境:debian 9官网提供了 deb,rpm,源码下载 官方下载地址:https://www.elastic.co/downloads/elasticsearch 通过源码安装会遇到一些小问题 ...
- 高斯消元part2
今天整一整高斯消元的模板,正经的 高斯消元主要用于解n元一次线性方程组与判断是否有解 主要思想? 就是高斯消元啊 主要思想是理想状态下消为每行除最后一项外只有一个1,并且每行位置互异,具体看下面. 这 ...