HDU 1028 HDU 1398 (母函数)
题意:输入一个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 (母函数)的更多相关文章
- 母函数 <普通母函数(HDU - 1028 ) && 指数型母函数(hdu1521)>
给出我初学时看的文章:母函数(对于初学者的最容易理解的) 普通母函数--------->HDU - 1028 例题:若有1克.2克.3克.4克的砝码各一 枚,能称出哪几种重量?各有几种可能方案? ...
- 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+ ...
- hdu 1028 & hdu 1398 —— 整数划分(生成函数)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1028 整数划分,每个数可以用无限次: 所以构造 f(x) = (1+x+x2+x3+...)(1+x2+x ...
- HDU 1028 HDU Ignatius and the Princess III
简单的钱币兑换问题,就是钱的种类多了一点,完全背包. #include<cstdio> #include<cstring> int main () { ]; memset(dp ...
- hdu 1028 母函数 一个数有几种相加方式
///hdu 1028 母函数 一个数有几种相加方式 #include<stdio.h> #include<string.h> #include<iostream> ...
- Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数
Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...
- HDU 1028 Ignatius and the Princess III (生成函数/母函数)
题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...
- 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种 ...
- 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 ...
随机推荐
- 跨域问题 Uncaught DOMException: Blocked a frame with origin。。。
第三方系统内嵌 到iframe中的 跨域问题. 解决方案: http://www.ruanyifeng.com/blog/2016/04/same-origin-policy.html
- 设计模式之————依赖注入(Dependency Injection)与控制反转(Inversion of Controller)
参考链接: 依赖注入(DI) or 控制反转(IoC) laravel 学习笔记 —— 神奇的服务容器 PHP 依赖注入,从此不再考虑加载顺序 名词解释 IoC(Inversion of Contro ...
- hbase系列之:独立模式部署hbase
一.概述 在上一篇博文中,我简要介绍了hbase的部分基础概念,如果想初步了解hbase的理论,可以参看上一篇博文 hbase系列之:初识hbase .本博文主要介绍独立模式下部署hbase及hbas ...
- python学习笔记2--list
一.list操作 list=['xiaohei','xiaobai','xiaohong']#定义一个数组 name=[]#定义一个空数组 #查 #下标是从0开始 print(list[1]) #-1 ...
- Redis学习四:解析配置文件 redis.conf
一.它在哪 地址: 思考:为什么要将它拷贝出来单独执行? 二.Units单位 1 配置大小单位,开头定义了一些基本的度量单位,只支持bytes,不支持bit 2 对大小写不敏感 三.INCLUDES包 ...
- 100baseT、100baseFX、1000base-SX、100/1000base-T
100baseT.100baseFX.1000base-SX.100/1000base-T 100baseT.100baseFX都是100Mbps速率基带传输系统,唯一的不同是100baseT用的是双 ...
- 34、Collections工具类简介
Collections工具类简介 就像数组中的Arrays工具类一样,在集合里面也有跟Arrays类似的工具类Collections package com.sutaoyu.Collections; ...
- plsql链接数据库配置
一. 目录结构 D:\install\PLSQL |-- instantclient_11_2 |-- tnsnames.ora |-- PLSQL ...
- pytorch--cnn的理解
class Model(nn.Module): def __init__(self): super(Model, self).__init__() self.conv1 = nn.Conv2d(1, ...
- 脚本病毒分析扫描专题1-VBA代码阅读扫盲、宏病毒分析
1.Office Macor MS office宏的编程语言是Visual Basic For Applications(VBA). 微软在1994年发行的Excel5.0版本中,即具备了VBA的宏功 ...