题目:http://acm.hdu.edu.cn/showproblem.php?pid=1028

就是可以用任意个1、2、3、...,所以式子写出来就是这样:(1+x+x^2+...)(1+x^2+x^4+...)(1+x^3+x^6+...)...(1+x^n+x^(2*n)+...)... 因为求 x^n 系数,所以再往后的式子就没有贡献了,求到第 n 个式子即可。

一个x^2就像一条边一样,可以让第 k 项的系数转移给第 k+2 项。按这个思路写代码就行了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int n,a[N],b[N];
int main()
{
while(scanf("%d",&n)==)
{
for(int i=;i<=n;i++)
a[i]=,b[i]=;
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
for(int k=;j+k<=n;k+=i)
b[j+k]+=a[j];
for(int j=;j<=n;j++)
a[j]=b[j],b[j]=;
}
printf("%d\n",a[n]);
}
return ;
}

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1398

同上。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=,M=;
int n,a[N],b[N],w[M+];
int main()
{
for(int i=;i<=M;i++)w[i]=i*i;
while()
{
scanf("%d",&n);if(!n)return ;
for(int i=;i<=n;i++)
a[i]=,b[i]=;
for(int i=;i<=M;i++)
{
for(int j=;j<=n;j++)
for(int k=;j+k<=n;k+=w[i])
b[j+k]+=a[j];
for(int j=;j<=n;j++)
a[j]=b[j],b[j]=;
}
printf("%d\n",a[n]);
}
}

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1085

感觉不从生成函数的角度看也可以很简单。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int n1,n2,n3;
bool a[N];
int main()
{
while()
{
scanf("%d%d%d",&n1,&n2,&n3);
if(!n1&&!n2&&!n3)return ;
int lm=n1+(n2<<)+n3*;
for(int i=lm+;i>n1;i--)a[i]=;//lm+1
for(int i=;i<=n1;i++)a[i]=;
for(int i=n1+(n2<<);i>n1;i--)
{
if(a[i])continue;
for(int j=min(n2<<,i-(i&));j>;j-=)
if(a[i-j]) {a[i]=;break;}
}
for(int i=lm;i>n1;i--)
{
if(a[i])continue;
for(int j=min(n3*,i/*);j>;j-=)
if(a[i-j]) {a[i]=;break;}
}
for(int i=n1+;i<=lm+;i++)
if(!a[i]){printf("%d\n",i);break;}
}
}

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1171

其实我就是写了一个很暴力的多重背包?

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=,M=N*N*;
int n,v[N],c[N];
bool a[M];
int main()
{
a[]=;
while()
{
scanf("%d",&n);if(n<)return ;
int sm=;
for(int i=;i<=n;i++)
scanf("%d%d",&v[i],&c[i]),sm+=v[i]*c[i];
for(int i=;i<=sm;i++)a[i]=;
sm=;
for(int i=;i<=n;i++)
{
sm+=v[i]*c[i];
for(int j=sm;j>;j--)
{
if(a[j])continue;
for(int k=;k<=c[i];k++)
{
if(k*v[i]>j)break;
if(a[j-k*v[i]]){a[j]=;break;}
}
}
}
int d=sm>>;
for(int i=d;i>=;i--)
if(a[i]){printf("%d %d\n",sm-i,i);break;}
}
}

hdu 1028 && hdu 1398 && hdu 1085 && hdu 1171 ——生成函数的更多相关文章

  1. hdu 1028 Ignatius and the Princess III【生成函数】

    老是想着化简,实际上O(n^3)就行了-- 写成生成函数是\( \prod_{i=1}^{n}(1+x^i+2^{2i}+...+x^{ \left \lfloor \frac{n}{i} \righ ...

  2. ACM: HDU 1028 Ignatius and the Princess III-DP

     HDU 1028 Ignatius and the Princess III Time Limit:1000MS     Memory Limit:32768KB     64bit IO Form ...

  3. hdu 1028 Ignatius and the Princess III 简单dp

    题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...

  4. HDU 1028 Ignatius and the Princess III (递归,dp)

    以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802  Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...

  5. hdu 1028 母函数 一个数有几种相加方式

    ///hdu 1028 母函数 一个数有几种相加方式 #include<stdio.h> #include<string.h> #include<iostream> ...

  6. Ignatius and the Princess III HDU - 1028 -生成函数or完全背包计数

    HDU - 1028 step 1:初始化第一个多项式 也就是 由 1的各种方案 组 成 的多项式 初始化系数为 1.临时区 temp初始化 为 0 step 2:遍历后续的n - 1 个 多项式 , ...

  7. Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数

    Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...

  8. HDU 1028 Ignatius and the Princess III (生成函数/母函数)

    题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...

  9. HDU 1028 Ignatius and the Princess III (动态规划)

    题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...

  10. 母函数 <普通母函数(HDU - 1028 ) && 指数型母函数(hdu1521)>

    给出我初学时看的文章:母函数(对于初学者的最容易理解的) 普通母函数--------->HDU - 1028 例题:若有1克.2克.3克.4克的砝码各一 枚,能称出哪几种重量?各有几种可能方案? ...

随机推荐

  1. [原创]spring及springmvc精简版--继承数据源,声明式事物

    1.前期:导入c3p0 jar包,相关数据库连接jar包,我用的是mysql 2.关注事物管理器的配置和AOP配置 代码: 核心关注bean配置文件 application.xml <?xml ...

  2. ==、equals与hashCode

    ==  首先,得说明java数据类型分为基本数据类型和引用数据类型, 基本数据类型有8种: 浮点型:float(4 byte), double(8 byte) 整型:byte(1 byte), sho ...

  3. iOS_多线程(二)

    上篇中我们分享了NSThread.NSOperation&NSOperationQueue如何实现多线程,今天我们来看下第三种实现多线程的方式:GCD(Grand Central Dispat ...

  4. Spring-data-jpa常用方法

  5. windows10添加电源计划修改的快捷方案

    转自:http://news.mydrivers.com/1/431/431346.htm 由于目前的Windows 10预览版在UI方面还未优化到位,所以某些设置选项要想找出来是很难的,这时候如果能 ...

  6. linux下bwa和samtools的安装与使用

    bwa的安装流程安装本软体总共需要完成以下两个软体的安装工作:1) BWA2) Samtools 1.BWA的安装a.下载BWA (download from BWA Source Forge ) h ...

  7. java中@Qualifier("string")是什么用法

    @Qualifier("XXX") Spring的Bean注入配置注解,该注解指定注入的Bean的名称,Spring框架使用byName方式寻找合格的bean,这样就消除了byTy ...

  8. 解析PHP中intval()等int转换时的意外异常情况

    <?php$a = 9.45*100;var_dump($a);var_dump(intval($a));$a = 945*1.00;var_dump($a);var_dump(intval($ ...

  9. 解决mssql for linux 中文乱码问题

    什么叫一波未平一波又起,这就是,好不容易安装完成了,在用的时候居然出现了乱码,很是头疼,但还是解决了这个蛋疼的问题,在windows中使用mssql这么久,从来没出现过中文乱码的情况,具体原因是出现在 ...

  10. 机器学习(二十七)— EM算法

    1.EM算法要解决的问题 如果使用基于最大似然估计的模型,模型中存在隐变量,就要用EM算法做参数估计. EM算法解决这个的思路是使用启发式的迭代方法,既然我们无法直接求出模型分布参数,那么我们可以先猜 ...