题目: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. XML文件结构和基本语法

    XML文件的结构性内容,包括节点关系以及属性内容等等.元素是组成XML的最基本的单位,它由开始标记,属性和结束标记组成.就是一个元素的例子,每个元素必须有一个元素名,元素可以若干个属性以及属性值. x ...

  2. Device Tree(一):背景介绍【转】

    本文转载自:http://www.wowotech.net/device_model/why-dt.html 一.前言 作为一个多年耕耘在linux 2.6.23内核的开发者,各个不同项目中各种不同周 ...

  3. iptables基础知识详解

    iptables防火墙可以用于创建过滤(filter)与NAT规则.所有Linux发行版都能使用iptables,因此理解如何配置 iptables将会帮助你更有效地管理Linux防火墙.如果你是第一 ...

  4. java 实现HTTP连接(HTTPClient)

    在实习中,使用到了http连接,一直理解的很模糊,特地写个分析整理篇.分析不到位的地方请多多指教. Http 目前通用版本为 http 1.1 . Http连接大致分为2种常用的请求——GET,POS ...

  5. Codeforces Round #366 (Div. 2) A , B , C 模拟 , 思路 ,queue

    A. Hulk time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  6. 微信内置浏览器http请求10秒内接收不到数据会自动重发第二遍请求

    微信内置浏览器http请求10秒内接收不到数据会自动重发第二遍请求     这是个坑

  7. 语音01_TTS

    1.http://blog.csdn.net/u010176014/article/details/47428595 2.家里 Win7x64 安装“微软TTS5.1语音引擎(中文).msi”之后,搜 ...

  8. pg_stat_activity存储postgresql当前连接个数

    postgres=# \d pg_stat_activity 视观表 "pg_catalog.pg_stat_activity" 栏位 | 型别 | 修饰词------------ ...

  9. Generator函数介绍

    Generator函数 基本概念 英文意思为 "生成器". generator函数是es6提供的一种异步编程解决方案,语法行为与传统函数完全不同.从状态上,首先我们把他理解成一种状 ...

  10. 10 个 SQL 注入工具

    BSQL Hacker BSQL Hacker是由Portcullis实验室开发的,BSQL Hacker 是一个SQL自动注入工具(支持SQL盲注),其设计的目的是希望能对任何的数据库进行SQL溢出 ...