HDOJ-1028-Ignatius and the Princess III 解题报告
来源:互联网 发布:linux禅道8.1安装教程 编辑:程序博客网 时间:2024/05/11 02:59
普通母函数基础题。题意:对于整数拆分问题,4有如下几种拆法
4 = 4
4 = 3 + 1
4 = 2 + 2
4 = 2 + 1 + 1
4 = 1 + 1 + 1 + 1
其中3 + 1和1 + 3属于同一种拆法。
现在给你一个数,问这个数有几种拆法。
我的解题思路:普通母函数题,令数字为x的指数,那么可以构造出母函数(1 + x + x^2 + ...)(1 + x^2 + x^4 + ...)...,
算出母函数序列后,x^n的系数就是n能被拆分的方法数了。
我的解题代码:
#include <cstdio>#include <cstdlib>#include <cstring>#include <cctype>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <map>using namespace std;const int N = 122;int coe[N], tmp[N];int n;void Init();int main(){ Init(); while (~scanf("%d", &n)) { if (n == 0) break; printf("%d\n", coe[n]); } return 0;}void Init(){ memset(coe, 0, sizeof(coe)); memset(tmp, 0, sizeof(tmp)); coe[0] = 1; for (int i=1; i<N; ++i) { for (int j=0; j<=120; ++j) { for (int k=0; k<N; ++k) { if (k * i + j > 120) break; tmp[k * i + j] += coe[j]; } } memcpy(coe, tmp, sizeof(coe)); memset(tmp, 0, sizeof(tmp)); } return;}
0 0
- HDOJ 1028 Ignatius and the Princess III解题报告
- HDOJ-1028-Ignatius and the Princess III 解题报告
- HDOJ 1028:Ignatius and the Princess III
- hdoj 1028 Ignatius and the Princess III
- 【HDOJ】1028 -> Ignatius and the Princess III
- HDOJ 1028 Ignatius and the Princess III
- hdoj 1028 Ignatius and the Princess III
- hdoj 1028 Ignatius and the Princess III
- HDOJ 1028 Ignatius and the Princess III
- hdoj-1028-Ignatius and the Princess III
- HDOJ 1028 Ignatius and the Princess III
- HDOJ 1029:Ignatius and the Princess IV 解题报告
- HDOJ 1026 Ignatius and the Princess I 解题报告
- HDOJ Ignatius and the Princess III
- HDOJ 1028 Ignatius and the Princess III [母函数]
- HDU/HDOJ 1028 母函数 Ignatius and the Princess III
- hdoj 1028 Ignatius and the Princess III(母函数)
- HDOJ 1028 Ignatius and the Princess III(DP)
- MongoDB基本使用
- HTTP请求返回状态码详解
- activiti 中的签收与委托 操作
- [nginx源码分析]hash 和header 回调初始化
- 利用检查点检查用户是否正确登陆
- HDOJ-1028-Ignatius and the Princess III 解题报告
- MSSql 与Oracle常用函数整理(一)
- android4.0以上版本监听home按键 通过监听log的方式监听home按钮
- How to judge the reused times of the film faced plywood
- JAVA 各种数值类型最大值和最小值 Int, short, char, long, float,&nbs
- 黑马程序员——Java基础——Set体系、Map体系操作等
- Android 屏幕适配方案
- LeetCode Course Schedule
- 几个简单的js实例