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 ...
随机推荐
- LazyMay:实现同步和异步任务的顺序执行
在掘金看到的文章,流程控制同步和异步任务的顺序执行,收益匪浅,工作中能用到. 1.实现以下效果 实现一个LazyMan,可以按照以下方式调用: LazyMan(“Hank”)输出: Hi! This ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik
http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...
- Django 2.0.1 官方文档翻译: 编写你的第一个 Django app,第四部分(Page 9)
编写你的第一个 Django app,第四部分(Page 9)转载请注明链接地址 该教程上接前面的第三部分.我们会继续开发 web-poll 应用,并专注于简单的表单处理和简化代码. 写一个简单的表单 ...
- Linux命令练习.ziw
2017年1月10日, 星期二 Linux命令练习 1.统计/usr/bin/目录下的文件个数: # ls /usr/bin | wc -l 判断 /home/goldin目录是否有文件 2.取出当前 ...
- HDU 1074 Doing Homework (dp+状态压缩)
题目链接 Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot ...
- shell if判断中常用的a-z表达式含义
shell if判断中常用的a-z表达式含义 可通过在在linux中man test命令查看下列参数的详细用法 [ -a FILE ] 如果 FILE 存在则为真. [ -b FILE ] 如果 ...
- Nginx配置location及rewrite规则
Nginx配置location及rewrite规则 示例: location = / { # 精确匹配 / ,主机名后面不能带任何字符串 [ configuration A ] } loca ...
- app横竖屏切换
问题: 使用react编写的页面,编译后的页面文件打包成app安装后,在手机上显示时,初次横竖屏切换时会出现页面尺寸渲染问题,要跳到其它页面后才能恢复,如图: 由竖屏切换成横屏后页面出现很多空白. 解 ...
- ubuntu 18.04 安装 flash
下载源码包, 解压 sudo cp Downloads/flash_player_npapi_linux.x86_64/libflashplayer.so /usr/lib/mozilla/plugi ...
- java系统的优化
1.tomcat.jboss.jetty的jvm内存,增大 2.数据库的优化,如MySQL的innodb_buffer_pool_size等参数,增大