题目: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. imx6solo wm8960始终没有声音输出

    我尝试各种办法,wm8960始终不能得到声音输出.调试过程如下: 首先,打开电源使能脚: ret=gpio_request(SABRESD_CODEC_PWR_EN,"audio_pwr_e ...

  2. U-Boot中支持USB

    转载: http://blog.csdn.net/qiurihuanghua/article/details/6234832 今天查看了一下在P4080DS板子的U-Boot中支持USB,主要是加入U ...

  3. java内置注解、元注解和自定义注解

    注解的作用: 1.生成文档 2.跟踪代码依赖性 3.编译时进行格式检查 ---------------------------------------------------------------- ...

  4. poj 1330 【最近公共祖先问题+fa[]数组+ 节点层次搜索标记】

    题目地址:http://poj.org/problem?id=1330 Sample Input 2 16 1 14 8 5 10 16 5 9 4 6 8 4 4 10 1 13 6 15 10 1 ...

  5. oracle 字典表查询

    1.oracle 字典表查询 /*显示当前用户*/ show user 在sql plus中可用,在pl sql中不可用 /*查看所有用户名*/ select username,user_id,cre ...

  6. HTTP与HTTPS有什么区别?

    HTTP协议传输的数据都是未加密的,也就是明文的,因此使用HTTP协议传输隐私信息非常不安全,为了保证这些隐私数据能加密传输,于是网景公司设计了SSL(Secure Sockets Layer)协议用 ...

  7. NCBI

    RefSeq: NCBI Reference Sequences GeneBank序列注释说明 利用NCBI查找基因信息 NCBI中RefSeq各种accession说明(一) NCBI中RefSeq ...

  8. HTML图片热区 map area 标签

    实例 <img src ="planets.gif" alt="Planets" usemap ="#planetmap" /> ...

  9. DelphiXE

    1. http://blog.csdn.net/tp26021340/article/details/45953669 2. 3. 4. 5.

  10. Java-集合类源码List篇(三)

    前言 前面分析了ArrayList和LinkedList的实现,分别是基于数组和双向链表的List实现.但看之前那张图,还有两个实现类,一个是Vector,另一个是Stack,接下里一起走进它们的源码 ...