题意:输入一个n  给出其所有组合数

如:

4 = 4;
  4 = 3 + 1;
  4 = 2 + 2;
  4 = 2 + 1 + 1;
  4 = 1 + 1 + 1 + 1;

重复不算

母函数入门题:

#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
using namespace std; #define N 505
#define inf 0x3f3f3f3f int c1[N]; //ans
int c2[N]; //中间变量 int main()
{
int n;
while(scanf("%d",&n)==)
{
for(int i=;i<=n;i++)
{
c1[i]=;
c2[i]=;
}
for(int i=;i<=n;i++)//i为第几个多项式 因为第一个多项式在上面已经初始化好了 接下来要做的是按照顺序将第i个多项式 与c1乘好
{
for(int j=;j<=n;j++)//c1数组的指数大小
for(int k=;j+k<=n;k+=i)//第i个多项式的各个指数值 这两个循环就是多项式乘法 时间:n*n
c2[j+k]+=c1[j]; for(int i=;i<=n;i++)
{
c1[i]=c2[i];
c2[i]=;
}
}
printf("%d\n",c1[n]);
}
return ;
}

和上面那题类似  只是这些人用平方值的硬币。

#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std; #define N 505
#define inf 0x3f3f3f3f int c1[N]; //ans
int c2[N]; //中间变量 int main()
{
int n;
while(scanf("%d",&n)==&&n)
{
for(int i=;i<=n;i++)
{
c1[i]=;
c2[i]=;
}
for(int i=;i<=sqrt(n);i++)//i为第几个多项式 因为第一个多项式在上面已经初始化好了 接下来要做的是按照顺序将第i个多项式 与c1乘好
{
for(int j=;j<=n;j++)//c1数组的指数大小
for(int k=;j+k<=n;k+=i*i)//第i个多项式的各个指数值 这两个循环就是多项式乘法 时间:n*n
c2[j+k]+=c1[j];
for(int i=;i<=n;i++)
{
c1[i]=c2[i];
c2[i]=;
}
}
printf("%d\n",c1[n]);
}
return ;
}

HDU 1028 HDU 1398 (母函数)的更多相关文章

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

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

  2. hdu 1028 && hdu 1398 && hdu 1085 && hdu 1171 ——生成函数

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1028 就是可以用任意个1.2.3....,所以式子写出来就是这样:(1+x+x^2+...)(1+x^2+ ...

  3. hdu 1028 & hdu 1398 —— 整数划分(生成函数)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1028 整数划分,每个数可以用无限次: 所以构造 f(x) = (1+x+x2+x3+...)(1+x2+x ...

  4. HDU 1028 HDU Ignatius and the Princess III

    简单的钱币兑换问题,就是钱的种类多了一点,完全背包. #include<cstdio> #include<cstring> int main () { ]; memset(dp ...

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

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

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

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

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

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

  8. hdu 1028 Ignatius and the Princess III

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 题目大意:3=1+1+1=1+2=3 :4=4=1+1+1+1=1+2+1=1+3:所以3有3种 ...

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

随机推荐

  1. SQL Server 属性不匹配。存在属性(Directory, Archive),包括属性(0),不包括属性(Archive, Compressed, Encrypted)

    问题:安装SQL SERVER 2008报错 “存在属性(Directory, Archive),包括属性(0),不包括属性(Archive, Compressed, Encrypted)” 解决办法 ...

  2. call 大佬 三分姿势

    为什么注释掉的三分方式不能过 @大佬 题目来源:http://hihocoder.com/problemset/problem/1142?sid=1003381 貌似不是eps的问题 #include ...

  3. poj 2125 Destroying The Graph (最小点权覆盖)

    Destroying The Graph http://poj.org/problem?id=2125 Time Limit: 2000MS   Memory Limit: 65536K       ...

  4. python学习笔记3-函数,判断负小数

    一.函数 def hello(file_name,content): #形参file_name content f=open(file_name,'a+') f.seek(0) f.write(con ...

  5. 正则表达式 grep文本查询 sed流处理 应用

    一.正则表达: ^:以什么什么开头,^a:以a字符开头 $:以什么什么结尾,b$:以b字符结尾 *:左边字符0-无穷个 +:左边字符1-无穷个 .:代表单字符 ?:前导字符为零个或1个 {n}:左面字 ...

  6. tensorflow中的卷积和池化层(一)

    在官方tutorial的帮助下,我们已经使用了最简单的CNN用于Mnist的问题,而其实在这个过程中,主要的问题在于如何设置CNN网络,这和Caffe等框架的原理是一样的,但是tf的设置似乎更加简洁. ...

  7. shell if判断中常用的a-z表达式含义

    shell if判断中常用的a-z表达式含义 可通过在在linux中man test命令查看下列参数的详细用法   [ -a FILE ] 如果 FILE 存在则为真. [ -b FILE ] 如果 ...

  8. NodeJS让前端与后端更友好的分手

    学问   最近“上层建筑”在兴起国学热,所以公司几个月前决定开发一款名叫“学问”的有关于国学的app.     APP的详情页面还是由web来显现具体内容,有些类似于新闻页,图文混排什么的web是最适 ...

  9. 原生的js实现jsonp的跨域封装

    一.原理 jsonp是利用浏览器请求script文件时不受同源策略的限制而实现的,伪造一个script标签,将请求数据的url赋值给script的src属性,并将该标签添加到html中,浏览器会自动发 ...

  10. 【bzoj题解】1012 最大数

    题目描述 现在请求你维护一个数列,要求提供以下两种操作:1.查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度.2.插入操作.语法:A ...