题意:输入一个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. 查看和修改linux系统时间

    一.查看和修改Linux的时区1. 查看当前时区 命令 : "date -R" 2. 修改设置Linux服务器时区方法 A 命令 : "tzselect" 方法 ...

  2. spring框架学习(六)AOP事务及spring管理事务方式之Template模板

    概念 1.事务 1)事务特性:ACID 原子性 :强调事务的不可分割. 一致性 :事务的执行的前后数据的完整性保持一致. 隔离性 :一个事务执行的过程中,不应该受到其他事务的干扰. 持久性 :事务一旦 ...

  3. postman pre-request-script 操作方法记录

    上代码----自己参考下就明白了 例子1:自动登陆获取token let chatHost,chatName,chatPassword;//设置环境变量 if (pm.environment.get( ...

  4. PHPCMS v9 安全防范教程!

    一.目录权限设置很重要:可以有效防范黑客上传木马文件.如果通过 chmod 644 * -R 的话,php文件就没有权限访问了.如果通过chmod 755 * -R 的话,php文件的权限就高了. 所 ...

  5. D. Easy Problem(简单DP)

    题目链接:http://codeforces.com/contest/1096/problem/D 题目大意:给你一个字符串,然后再给你去掉每个字符串的每个字符的花费,然后问你使得字符中不再存在har ...

  6. vue+hbuilder监听安卓返回键问题

    1.监听安卓返回键问题 效果:在一级页面按一下返回键提示退出应用,按两下退出应用;在其它页面中,按一下返回上个历史页面 1 2 import mui from './assets/js/mui.min ...

  7. translate 与 相对、绝对定位

    垂直水平居中是日常前端开发当中一个常见的需求,在支持 CSS3 属性的现代浏览器当中,有一个利用 CSS3 属性的垂直水平居中方法: position absolute; :; :; :transla ...

  8. 命名实体识别(NER)

    一.任务 Named Entity Recognition,简称NER.主要用于提取时间.地点.人物.组织机构名. 二.应用 知识图谱.情感分析.机器翻译.对话问答系统都有应用.比如,需要利用命名实体 ...

  9. 用Max导出Unity3D使用的FBX文件流程注解(转载)

    http://www.cnblogs.com/wantnon/p/4564522.html 从max导出FBX到Unity,以下环节需要特别注意.1,单位设置   很多人在建模,动画的时候,默认的ma ...

  10. Animate.css 前端动画开发教程

    1.首先下载animate.css文件: 2.打开动画预览地址选择想要的动画,地址:https://daneden.github.io/animate.css/  ,选择好后记住动画的名字在你下载的a ...