Ignatius and the Princess III hdoj 1028 (母函数初学)
来源:互联网 发布:网络事件驱动 编辑:程序博客网 时间:2024/04/28 00:34
Ignatius and the Princess III hdoj 1028 (母函数初学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028
题目大意: 求一个整数能拆分的方法总数。
题目思路: 反向的母函数麽,跟1085题的不同处,我来解析下。
1085题是给你 分解的“单位值”(1,3,5),和其个数,求其最小不能组成的数;
1028题是给你 最终组成的数,问你其分解的方法总数。转言之,其分解的“单位值”可以是1到它本身的数,而且单位值的个数不限,也可以是0。
分析了差别,我们可以知道,此题可以用(1到n)都组合乘一遍,最终c1[n]的值就为拆分方法总数。
ac代码
#include <stdio.h>#include <string.h>#include <algorithm>#include <iostream>using namespace std;#define N 121int c1[N],c2[N];int main(){ int n; while(cin >> n) { for(int i=0;i<=n;i++) c1[i] = 1; //从第二个表达式开始,第i个表达式 for(int i=2;i<=n;i++) { //j表示进行一次表达式相乘后,第一个表达式的的第j个变量 for(int j=0;j<=n;j++) { for(int k=0;k+j<=n;k+=i)//此处表示第一个表达式的第j个变量遍历第I个表达式. c2[k+j] += c1[j];//c1[j]存储的是上一次指数为j的系数,因为第二个表达式的所有的系数均为1,其实就是将拥有k+j指数的系数加1. } for(int j=0;j<=n;j++) { c1[j] = c2[j]; c2[j] = 0; } //将c2存储的系数赋值给相应的c1,然后清零c2. } cout << c1[n] << endl; } return 0;}
若还是不清楚请看我转载的母函数理论知识。
0 0
- Ignatius and the Princess III hdoj 1028 (母函数初学)
- 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(母函数)
- hdoj-1028 Ignatius and the Princess III【母函数】
- HDOJ--1028Ignatius 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 题目1028Ignatius and the Princess III(母函数模板)
- HDOJ 1028 Ignatius and the Princess III(母函数—整数拆分模板题)
- JAVA--简易聊天室程序
- 79-命名空间
- 9轴陀螺仪KF系列算法的轴向问题
- 80-定义接口
- "Cannot declare member function ...to have static linkage"错误
- Ignatius and the Princess III hdoj 1028 (母函数初学)
- 函数指针回调函数
- 81-继承与实现接口
- hiho 52 连通性一·割边与割点
- 详解ARM的AMBA设备中的DMA设备(Linux驱动之DMA)
- Android安装
- mxnet深度学习(KVS)
- 82-资源resource类型
- ios 集成 支付宝 遇到的各种问题 总结