[省选前题目整理][HDU 1028]Ignatius and the Princess III(生成函数)
来源:互联网 发布:淘宝开食品店要求 编辑:程序博客网 时间:2024/04/26 12:58
题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=1028
题目大意
给出一个数字
比如,对于
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
思路
很容易构造出
那么最终我们构造一个多项式
这个生成函数的解法可以通过FFT或者是暴力的多项式乘法实现,但是鉴于此题范围很小,下面引出一个更简单好写的做法。
可以把每个数字
其实这个做法就是暴力的多项式乘法,只不过写法简化了很多而已。
代码
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <algorithm>#define MAXN 40020using namespace std;int c1[MAXN],c2[MAXN];int num[MAXN],money[MAXN];int main(){ int n; while(scanf("%d",&n)!=EOF) { int max=0; //多项式的最高次项 for(int i=1;i<=n;i++) { money[i]=i; num[i]=n/i; } memset(c1,0,sizeof(c1)); //c1:老多项式 memset(c2,0,sizeof(c2)); //c2:新多项式 c1[0]=1; for(int i=1;i<=n;i++) { for(int j=0;j<=max;j++) for(int k=0;k<=num[i];k++) c2[j+k*money[i]]+=c1[j]; max+=num[i]*money[i]; memcpy(c1,c2,sizeof(c2)); memset(c2,0,sizeof(c2)); } printf("%d\n",c1[n]); } return 0;}
0 0
- [省选前题目整理][HDU 1028]Ignatius and the Princess III(生成函数)
- hdu 1028 Ignatius and the Princess III(生成函数)
- 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 母函数
- C++ 的placement new语法
- Java-时间格式
- android.content.ActivityNotFoundException: No Activity found to handle Inte
- 如何判断一个数是否是2的n次方
- typedef 用法详解(二)
- [省选前题目整理][HDU 1028]Ignatius and the Princess III(生成函数)
- CSS字体
- ns2仿真的一个入门实例(整理归纳自网络资源)
- 第二章21题(水仙花数)
- [Android] ViewDragHelper -- 能做什么
- Android版本和API Level对应关系
- CSS—浮动
- Android Studio Gradle UserGuide
- 从小到大按顺序输出七个数