从hdu 1028 Ignatius and the Princess III看母函数
来源:互联网 发布:51单片机的引脚 编辑:程序博客网 时间:2024/05/18 11:25
题目链接
母函数一般用于排列组合问题。
对于一般组合问题,序列{ai}的生成函数为:a0 + a1 * x + a2 * x ^ 2 + a3 * x ^3 + .....
对于排列问题,需要定于另外一种指数生成函数:
对于一般组合问题,如hdu 1028 Ignatius and the Princess III
该题的母函数为
(1+x+x^2+x^3...) * (1+x^2+x^4+x^6....) * (1+x^3+x^6+x^9.....) * (1+x^4+x^8+x^12.....)
其解就是 x ^ n 的系数。啊噢,为什么,给个链接吧:传送门
至于把多项式解出来,也是有技巧的,见代码:
#include<stdio.h>int m1[124],m2[124];//m1[i]记录x次数位i的系数,m2[]是一个中转的便于计算 void mn( int n ){for( int i = 0; i <= n; ++i ){m1[i] = 1;m2[i] = 0;}for( int i = 2; i <= n; ++i ) //难点{//总共有n个括号,从第2个起每一个括号都要和前面那一个括号相乘//所以可以忽略第一个括号 for( int j = 0; j <= n; ++j )//j代表最前面这个大括号的项数 for( int k = 0; k + j <= n; k += i )//在大括号后面,x都是以i方递增的 m2[j + k] += m1[j];//这里就是大括号后面的括号与前面相乘的计算 for( int j = 0; j <= n; ++j ){//算完以后都存在m2里面,所以要把值赋给m1, m1[j] = m2[j];m2[j] = 0;}}}int main( ){mn( 123 );int n;while( scanf( "%d",&n ) != EOF )printf( "%d\n",m1[n] );//x^n的系数就代表和为n的组合数 return 0;}
0 0
- 从hdu 1028 Ignatius and the Princess III看母函数
- HDU/HDOJ 1028 母函数 Ignatius and the Princess III
- HDU 1028 Ignatius and the Princess III(母函数)
- HDU 1028 Ignatius and the Princess III (母函数)
- HDU-1028Ignatius and the Princess III(母函数)
- hdu 1028 Ignatius and the Princess III 母函数
- hdu 1028 Ignatius and the Princess III(母函数)
- hdu 1028 Ignatius and the Princess III 母函数
- HDU 1028 Ignatius and the Princess III(母函数)
- [母函数]HDU 1028 Ignatius and the Princess III
- [hdu 1028] Ignatius and the Princess III (母函数)
- hdu 1028 Ignatius and the Princess III 母函数/dp
- Ignatius and the Princess III 【HDU--1028-母函数】
- hdu 1028 Ignatius and the Princess III ( 母函数)
- hdu 1028 Ignatius and the Princess III (母函数)
- HDU 1028 Ignatius and the Princess III 母函数
- hdu-1028 Ignatius and the Princess III 【母函数】
- HDU -- 1028 Ignatius and the Princess III(母函数)
- codeforce 416/B 动态规划简单题
- LAMP环境搭建遇到的问题解决方案
- BoneCollector-01背包
- 最好的年龄
- percona 初始化报错error while loading shared libraries: libssl.so.6
- 从hdu 1028 Ignatius and the Princess III看母函数
- 创业风险
- WebGL入门教程第1篇——六色立方
- 十大算法
- BMFont中文字体图集制作的方法~(for unity ngui)
- c++内存中字节对齐问题详解
- QAction怎么样第一次点击的时候保持按下状态
- 春天防治“上火”8个败火小妙招
- 将参数传给UIAlertView的 Delegate