hdu 1028 整数划分 (母函数)
假如输入4
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
一共5种
假如输入3 用母函数的方法就是写成
(1+X+X2+X3)(1+X2)(1+X3) 展开后 求X3的系数
假如输入n
就是(1+X+X2+X3+X4....)(1+X2+X4+X6..)(1+X3+X6...)(....)
Sample Input
4
10
20
Sample Output
5
42
627
# include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <string>
# include <cmath>
# include <queue>
# include <list>
# define LL long long
using namespace std ; int c1[], c2[] ;
int main()
{
//freopen("in.txt","r",stdin) ;
int n;
int i, j, k;
while(cin >> n)
{
for(i=; i<=n; ++i)
{
c1[i] = ;
c2[i] = ;
}
for(i=; i<=n; ++i)
{ for(j=; j<=*n; ++j)
for(k=; k <= *n; k += i)
{
c2[j+k] += c1[j];
}
for(j=; j<=n; ++j)
{
c1[j] = c2[j];
c2[j] = ;
}
}
cout << c1[n] << endl;
}
return ;
}
hdu 1028 整数划分 (母函数)的更多相关文章
- hdu 1028 & hdu 1398 —— 整数划分(生成函数)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1028 整数划分,每个数可以用无限次: 所以构造 f(x) = (1+x+x2+x3+...)(1+x2+x ...
- Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数
Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...
- HDU 1028 整数拆分 HDU 2082 找单词 母函数
生成函数(母函数) 母函数又称生成函数.定义是给出序列:a0,a1,a2,...ak,...an, 那么函数G(x)=a0+a1*x+a2*x2+....+ak*xk +...+an* xn 称为序 ...
- 母函数 <普通母函数(HDU - 1028 ) && 指数型母函数(hdu1521)>
给出我初学时看的文章:母函数(对于初学者的最容易理解的) 普通母函数--------->HDU - 1028 例题:若有1克.2克.3克.4克的砝码各一 枚,能称出哪几种重量?各有几种可能方案? ...
- hdu 1398 整数划分变形 (母函数)
有1,4,9,16,25.....2^17这么多面值的硬币,问任意给定一个不大于300的正整数面额,用这些硬币来组成此面额总共有多少种组合种数 比如10全14 + 6个 14+4+1+19+1 求(1 ...
- hdu,1028,整数拆分的理解
#include"iostream"using namespace std;int main() { int n,i,j,k; int c[122],temp[122]; //c[ ...
- HDU acm1028 整数划分 递归问题(递推)
我们用递归+记忆化的方法来解决普通整数划分问题:定义 f(n,m)为将整数n划分为一系列整数之和,其中加数 最大不超过m. 得到下面的递推关系式: 当n==1 || m==1 只有一种划分,即 1 或 ...
- hdu 5230 整数划分 dp
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5230 题意:给定n,c,l,r.求有多少种方法从1~n-1选取任意k数每个数的权重为其下标,使得这些数字之 ...
- HDU 1028 整数拆分问题 Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
随机推荐
- Betsy Ross Problem
Matlab学习中的betsy ross 问题.用matlab函数画1777年的美国国旗. 五角星绘制部分是自己想出来的方法去画上的.具体代码参考如下. 先是绘制矩形的函数 function Draw ...
- 【Asp.net入门5-03】创建产品清单
- Eloquent 条件查询——tucker-eric/eloquentfilter 笔记
请阅读 https://github.com/Tucker-Eric/EloquentFilter , 里面有很全的文档和注释,以下仅列出关键部分. 1. 安装 composer require tu ...
- 利用Confluence搭建企业Wiki
Confluence安装与部署 下载安装包及破解包 安装包下载地址:https://www.atlassian.com/software/confluence/download-archives 破解 ...
- 服务器安全策略之《通过IP安全策略阻止某个IP访问的设置方法》
现在我们在布署好了一个网站,发布到外网后就意味着将会接受来自四面八方的黑客攻击,这个情况很常见,我们的网站基本上每天都要接受成千上万次的攻击,有SQL注入的.有代码注入的.有CC攻击等等...而我作为 ...
- bootstrap-switch
首先需要引入bootstrap的css和js文件,再引入bootstrap-switch.css和bootstrap-switch.js文件 <script type="text/ja ...
- tomcat修改java不重启
修改tomcat server.xml 找到项目的Context配置 <Context docBase="项目名" path="/项目路径" relo ...
- 2008ZJOI树的统计
codevs 2460 树的统计 http://codevs.cn/problem/2460/ 2008年省队选拔赛浙江 题目等级 : 大师 Master 题目描述 Description 一棵 ...
- noi题库(noi.openjudge.cn) 1.11编程基础之二分查找T01、02、04
T01 查找最接近的元素 描述 在一个非降序列中,查找与给定值最接近的元素. 输入 第一行包含一个整数n,为非降序列长度.1 <= n <= 100000.第二行包含n个整数,为非降序列各 ...
- URL访问 和命名规范
手册:http://v9.help.phpcms.cn/html/2010/structure_0928/71.html http://yourdomain.com/index.php?m=conte ...