HDU 1028 整数拆分 HDU 2082 找单词 母函数
生成函数(母函数)
母函数又称生成函数。定义是给出序列:a0,a1,a2,...ak,...an,
那么函数G(x)=a0+a1*x+a2*x2+....+ak*xk +...+an* xn 称为序列a0,a1,a2,.......ak,......的母函数(即生成函数)。
1. 问题 n=x1+x2+x3+...+xk有多少个非负整数解?这道题是学排列与组合的经典例题了。
把每组解的每个数都加1,就变成n+k=x1+x2+x3+...+xk的正整数解的个数了。
教材上或许会出现这么一个难听的名字叫“隔板法”:把n+k个东西排成一排,在n+k-1个空格中插入k-1个“隔板”。
答案我们总是知道的,就是C(n+k-1,k-1)。它就等于C(n+k-1,n)。
它关于n的生成函数是g(x)=1/(1-x)^k。
2. 这个公式非常有用,是把一个生成函数还原为数列的武器。而且还是核武器。1/(1-x)^n=1+C(n,1)x^1+C(n+1,2)x^2+C(n+2,3)x^3+...+C(n+k-1,k)x^k+...。
找单词
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9784 Accepted Submission(s): 6805
然后包括N行数据,每行包括26个<=20的整数x1,x2,.....x26.








#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define huan printf("\n");
#define debug(a,b) cout<<a<<" "<<b<<" "<<endl;
using namespace std;
const int maxn= 1e2+;
const int inf = 0x3f3f3f3f;
typedef long long ll;
ll a[maxn],b[maxn];
int main()
{
int t;
cin>>t;
while(t--)
{
fillchar(a,);
fillchar(b,);
a[]=;
for(int i=;i<=;i++)
{
int x;
cin>>x;
for(int j=;j<=;j++)
{
for(int k=;k<=x&&(j+i*k<=);k++)
{
b[j+k*i]+=a[j];
} }
for(int j=;j<=;j++)
{
a[j]=b[j];
b[j]=;
}
}
ll ans=;
for(int i=;i<=;i++)
{
ans+=a[i];
}
cout<<ans<<endl;
}
}
Ignatius and the Princess III
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25750 Accepted Submission(s): 17803
"The second problem is, given an positive integer N, we define an equation like this:
N=a[1]+a[2]+a[3]+...+a[m];
a[i]>0,1<=m<=N;
My question is how many different equations you can find for a given N.
For example, assume N is 4, we can find:
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
so the result is 5 when N is 4. Note that "4 = 3 + 1" and "4 = 1 + 3" is the same in this problem. Now, you do it!"
递推法


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define huan printf("\n");
#define debug(a,b) cout<<a<<" "<<b<<" "<<endl;
using namespace std;
const int maxn= 1e2+;
const int inf = 0x3f3f3f3f;
typedef long long ll;
ll a[maxn],b[maxn];
int main()
{
int n;
while(cin>>n)
{
fillchar(a,);
fillchar(b,);
a[]=;
for(int i=;i<=n;i++) //枚举第i个多项式 每一项的系数都为1
{
for(int j=;j<=n;j++) //保留x0----xn项
{
for(int k=;j+i*k<=n;k++) //枚举第i个多项式的每一项
{
b[j+k*i]+=a[j]; //b数组保存中间值
} }
for(int j=;j<=n;j++)
{
a[j]=b[j]; //b数组传值给a
b[j]=;
}
}
cout<<a[n]<<endl;
}
}
/*----------------------------------------------------------------------------------------*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
//记忆化递归法求解整数划分
ll ans[][];
ll GetPartitionCount(int n, int m)
{
if(ans[n][m]>)
return ans[n][m];
if (n == || m == )return ans[n][m]=;
if (n < m)return ans[n][m]=(GetPartitionCount(n, n));
if (n == m)return ans[n][m]=( + GetPartitionCount(n, n - ));
else return ans[n][m]=(GetPartitionCount(n - m, m) + GetPartitionCount(n, m - ));
} int main()
{
int n,m;
ll sum;
while (scanf("%d",&n)==)
{
memset(ans,,sizeof(ans));
m=n;
sum = GetPartitionCount(n, m);
printf("%lld\n", sum);
}
return ;
}
HDU 1028 整数拆分 HDU 2082 找单词 母函数的更多相关文章
- Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数
Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...
- HDOJ 2082 找单词 (母函数)
找单词 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu,1028,整数拆分的理解
#include"iostream"using namespace std;int main() { int n,i,j,k; int c[122],temp[122]; //c[ ...
- 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 2082 找单词 (普通型 数量有限 母函数)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2082 找单词 Time Limit: 1000/1000 MS (Java/Others) Me ...
- hdu acm 2082 找单词
找单词 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 1028 Ignatius and the Princess III(母函数整数拆分)
链接:传送门 题意:一个数n有多少种拆分方法 思路:典型母函数在整数拆分上的应用 /********************************************************** ...
- HDU 1028 Ignatius and the Princess III (生成函数/母函数)
题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...
- hdu2082 找单词 (母函数)
找单词 题意: 中文题,考虑是不是要写个英文题意..(可惜英语水平不够 囧rz) (题于文末) 知识点: 母函数(生成函数): 生成函数有普通型生成函数和指数型生成函数 ...
随机推荐
- iOS圆形图片裁剪,原型图片外面加一个圆环
/** * 在圆形外面加一个圆环 */ - (void)yuanHuan{ //0.加载图片 UIImage *image = [UIImage imageNamed:@"AppIcon1 ...
- npm安装使用及vue脚手架安装
公司在前端用vue开发项目,那就学习下啦,第一步,在安装vue-devtools过程中,npm作为官方manual installtion方式,肯定必不可少. NPM是随同NodeJS一起安装的包管理 ...
- 洛谷 P1011 车站
题目描述 火车从始发站(称为第1站)开出,在始发站上车的人数为a,然后到达第2站,在第2站有人上.下车,但上.下车的人数相同,因此在第2站开出时(即在到达第3站之前)车上的人数保持为a人.从第3站起( ...
- EOS Dawn 3.0 智能合约 -- 新格式
1.简介 随着EOS Dawn 3.0发布,智能合约的坑又要重新踩了o(╥﹏╥)o:3.0不仅将原来本身就在链里的基础合约独立出来,简单的介绍见3.0合约改变,合约的书写方式也有巨大变化,相比之前更加 ...
- Socket网络编程初探
http://altboy.blog.51cto.com/5440160/1921720 客户端/服务器架构 即C/S架构,其实web服务在某种意义上也算是C/S架构 一个特点是服务器端持续运行对外提 ...
- 总结vue2.0 配置的实例方法
总结vue2.0 配置的实例方法 http://www.php.cn/js-tutorial-369603.html
- Keil Debug (printf) Viewer
Debug (printf) Viewer Home » µVision Windows » Debug (printf) Viewer The Debug (printf) Viewer windo ...
- New Arrival MB SD Connect Compact 5 (MB SD C4) Star Diagnosis
MB SD Connect Compact 5 has same function as SD C4 but with new design, support both cars and trucks ...
- 欧拉函数 || LightOJ 1370 Bi-shoe and Phi-shoe
给出x,求最小的y使y的欧拉函数大于等于x *解法:i).求出1e6之内的数的欧拉函数,遍历找 ii).求比x大的第一个质数——因为每个质数n的欧拉函数都是n-1 wa一次是因 ...
- 输入3个数a,b,c,按大小顺序输出。
题目:输入3个数a,b,c,按大小顺序输出. 思路: 根据最简单的, 经典的C语言算法, 两两相互交换得到他们的顺序 public class 第三十四题abc三个数大小排序 { public sta ...