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.
+
…
) (1+
+
+…
)…(1+
+…
) 每一个多项式 i 有xi+1项 然后多项式乘法就好了#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!"
递推法
的值为多少(n>0),只有一种划分,即{1,1,....1,1,1};
的情况,即{m,{x1,x2,x3,...,xi}},其中{x1,x2,x3,...,xi}的和为n-m,可能再次出现m,因此是(n-m)的m划分,因此这种划分个数为f(n-m,m;#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) (题于文末) 知识点: 母函数(生成函数): 生成函数有普通型生成函数和指数型生成函数 ...
随机推荐
- 使用代码编辑器Sublime Text 3进行前端开发及相关快捷键
推荐理由: Sublime Text:一款具有代码高亮.语法提示.自动完成且反应快速的编辑器软件,不仅具有华丽的界面,还支持插件扩展机制,用她来写代码,绝对是一种享受.相比于浮肿沉重的Eclipse, ...
- SQLite_安装
SQLite -安装 zero-configuration SQLite闻名的特性,这意味着不需要复杂的设置或管理.本章将带你通过设置SQLite的过程在Windows.Linux和Mac OS X. ...
- swift 泛型的类型约束
总结: 1.类型约束只能添加到泛型参量上面 2.关联类型是泛型参量: 3.关联类型可以通过 协议.关联类型名称的形式引用: func allItemsMatch<C1: Container, C ...
- Linux之基础命令——文件搜索
grep(匹配符合条件的字符串) 无参:显示匹配行 -c:显示匹配行数 -e 字符串:匹配特殊字符串,如-开头 -i:忽略大小写 -v:输出不匹配行 -w:匹配指定字符串 可以和别的命令通过" ...
- python基础一 day5 知识点
Unicode转化为gbk和utf-8 表现形式:str转化为bytes
- struct获取不到值的小错误
struct2 get set 这两个方法一定要用双骆驼命名法:getA() setA(), 而geta() seta()不行 我找了好久的错误,只能说框架这东西快捷方便,找起错误要人命
- github下拉刷新与上拉加载地址
https://github.com/chrisbanes/Android-PullToRefresh
- js检测对象是否是数组
js检测对象是否是数组 可以通过instanceof 方法一. var arr=[] arr instanceof Array //true var obj={} obj instanceof A ...
- Android开发中JavaBean类和序列化知识的理解
原创文章,转载请注明出处:http://www.cnblogs.com/baipengzhan/p/6296121.html Android开发中,我们经常用到JavaBean类以及序列化的知识,但经 ...
- Cookie 详解以及实现一个 cookie 操作库
Cookie 详解以及实现一个 cookie 操作库 cookie 在前端有着大量的应用,但有时我们对它还是一知半解.下面来看看它的一些具体的用法 Set-Cookie 服务器通过设置响应头来设置客户 ...