题目: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. $.cssHooks 扩展 jquery 的属性操作

    最近在研究 $.transit 然后发现了 $.cssHooks 这个方法,试了一下官方的 demo 表示好像并不是那么回事,所以决定深入的测试一下. $.cssHooks 的作用在于拓展属性(自己意 ...

  2. MySql 5.7 详细参数说明

    max_connections: 允许客户端并发连接的最大数量,默认值是151,一般将该参数设置为500-2000 max_connect_errors: 如果客户端尝试连接的错误数量超过这个参数设置 ...

  3. mysql的一些密码错误问题,并从windows登录linux主机的mysql

    mysqld_safe --skip-grant-tables& mysql -u root mysql 可以修改密码: mysql>update mysql.user set auth ...

  4. 基于Visual c++ 2012的php扩展开发 - HelloWord!

    1.cmd进入命令行模式,并进入php-5.6.20-src/ext源代码的ext目录下输入命令php ext_skel_win32.php --extname=HelloWord,执行结果如下图: ...

  5. c# 图片 与 BASE64 字符串 互相转换。

    using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System. ...

  6. seajs 入门

    最近想搞搞JS模块化, 读到了园子里的一篇好文:  http://www.cnblogs.com/lvdabao/p/js-modules-develop.html 看里面讲seajs不错, 于是想学 ...

  7. java写出图形界面

    1. 做出简单的窗体 package javaGUI; import java.awt.BorderLayout; import java.awt.Color; import javax.swing. ...

  8. Excel下载打不开

    1.问题描述:今天遇到个问题,对于定时发送邮件,前两天还正常,今天发现邮件能收到,但打不开,显示如下错误: 预览邮件显示: 点击Excel打开,显示如下: 2.问题解决方案 删除对于服务器上部分空间内 ...

  9. 常见Web安全漏洞

    1.web安全常见攻击手段     xss  sql注入  防盗链  csrf  上传漏洞 2. 信息加密与漏洞扫描   对称加密 非对称加密 3. 互联网API接口安全设计 4. 网站安全漏洞扫描与 ...

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

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