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 ...
随机推荐
- Spring boot学习总结
引言之前也没有深入学习过spring框架,最近SpringBoot流行起来后想补下这方面的知识,于是照着SpringBoot官网上的英文教程开始helloworld入门,踩到几个小坑,记录下学习流程. ...
- ArcGis10.1 Feature Class Properties无法编辑
被这个问题困扰了很久,最后从官网帮助中查询到资料解决了 先看一下截图: 这种问题一般是FratureClass被锁,被mxd引用,并且发布服务有实例在运行,但我新创建一个FeatureClass也无法 ...
- 20155227 2016-2017-2 《Java程序设计》第七周学习总结
20155227 2016-2017-2 <Java程序设计>第七周学习总结 教材学习内容总结 认识时间与日期 时间的度量 世界时:在1972年引入UTC之前,GMT与UT是相同的. 国际 ...
- 【leetcode 简单】 第九十七题 快乐数
写一个程序,输出从 1 到 n 数字的字符串表示. 1. 如果 n 是3的倍数,输出“Fizz”: 2. 如果 n 是5的倍数,输出“Buzz”: 3.如果 n 同时是3和5的倍数,输出 “FizzB ...
- HDU 1251 统计难题 (裸的字典树)
题目链接 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本 ...
- C# XML序列化和反序列化
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- html5 构造网页的新方式
从 html 诞生至今,我们构建 html 页面的使用 html 元素好像并没有太多的进步.在构建 html 页面中,用的最多的是 div 标签.但是应用 div 标签构建 html 页面有一个问题, ...
- QByteArray储存二进制数据(包括结构体,自定义QT对象)
因为利用QByteArray可以很方便的利用其API对内存数据进行访问和修改, 构建数据库blob字段时必不可少; 那如何向blob内写入自定义的结构体和类 //自定义person结构体 typede ...
- bzoj 1014: 洛谷 P4036: [JSOI2008]火星人
题目传送门:洛谷P4036. 题意简述: 有一个字符串,支持插入字符,修改字符. 每次需要查询两个后缀的LCP长度. 最终字符串长度\(\le 100,\!000\),修改和询问的总个数\(\le 1 ...
- JDk1.8源码StringBuffer
一.概念 StringBuffer A thread-safe, mutable sequence of characters. A string buffer is like a {@link St ...