题目: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. Linux软件包管理 RMP包管理

    概述 RPM 包的命名一般都会遵守统一的命名规则,例如: httpd-2.2.15-15.el6.centos.1.i686.rpm 其中的各项代表的含义如下: httpd:软件包名. 2.2.15: ...

  2. Android中设置自己软件的铃声+震动

    有时候一些通讯软件需要这些个功能,比如说收到短信,通知等,要求手机发出铃声,或震动,或发光以提示用户知晓. 往往手机都是有默认设置的,比如说用户开启了铃声+震动:只铃声不震动:完全静音等等... 这个 ...

  3. poj 3126 Bfs

    Prime Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14539   Accepted: 8196 Descr ...

  4. 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 ...

  5. Codeforces Round #304 (Div. 2) D. Soldier and Number Game 素数打表+质因数分解

    D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input s ...

  6. watcher

    https://wiki.openstack.org/wiki/Watcher Watcher为OS提供资源优化.主要是通过虚拟机迁移来提高整个数据中心的运营效率,降低TCO. 功能特点: 通过虚拟机 ...

  7. nova Rescue 和 Unrescue

    usage: nova rescue [--password <password>] [--image <image>] <server> Reboots a se ...

  8. Hadoop- Namenode经常挂掉 IPC's epoch 9 is less than the last promised epoch 10

    如题出现Namenode经常挂掉 IPC's epoch 9 is less than the last promised epoch 10, 2019-01-03 05:36:14,774 INFO ...

  9. JDK与JRE及其在Eclipse中的使用

    转载自:http://blog.csdn.net/gx1058742912/article/details/51033942 JDK与jRE的区别 JDK(java development kit): ...

  10. 元数据(MetaData)

    元数据是用来描述数据的数据(Data that describes other data).单单这样说,不太好理解,我来举个例子. 下面是契诃夫的小说<套中人>中的一段,描写一个叫做瓦莲卡 ...