hdu 1028 Ignatius and the Princess III(母函数)
题意:
N=a[1]+a[2]+a[3]+...+a[m];
a[i]>0,1<=m<=N;
例如:
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
共有5种。
给N,问共有几种构造方式。
思路:
一个数N分解的式子中1的个数可以是0,1,2,3,...,N。
2的个数可以是0,1,2,...,N/2。
....
母函数基础题,,
看代码。
当然也可以用DP(背包)
母函数代码:
int N,num;
int a[200],b[200]; int main(){
while(cin>>N){
memset(a,0,sizeof(a)); a[0]=1; memset(b,0,sizeof(b));
for(int i=1;i<=N;++i){
for(int j=0;j<=N;++j)
for(int k=0;k+j<=N;k+=i) b[j+k]+=a[j];
for(int j=0;j<=N;++j){ a[j]=b[j]; b[j]=0; }
}
cout<<a[N]<<endl;
}
}
hdu 1028 Ignatius and the Princess III(母函数)的更多相关文章
- hdu 1028 Ignatius and the Princess III 母函数
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu 1028 Ignatius and the Princess III 简单dp
题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...
- HDU 1028 Ignatius and the Princess III 整数的划分问题(打表或者记忆化搜索)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1028 Ignatius and the Princess III Time Limit: 2000/1 ...
- HDU 1028 Ignatius and the Princess III (母函数或者dp,找规律,)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu 1028 Ignatius and the Princess III(DP)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu 1028 Ignatius and the Princess III (n的划分)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- 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 (递归,dp)
以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802 Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...
- 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:dp or 母函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 题意: 给你一个正整数n,将n拆分成若干个正整数之和,问你有多少种方案. 注:"4 = ...
随机推荐
- 洛谷P1160——队列安排(双向链表)
题目描述 一个学校里老师要将班上N个同学排成一列,同学被编号为1-N,他采取如下的方法: 1.先将1号同学安排进队列,这时队列中只有他一个人: 2.2-N号同学依次入列,编号为i的同学入列方式为:老师 ...
- 【C++】特殊字符“\0”,以及NULL相关
我们都知道,'\0'是字符串的结束标记.因此,执行这段代码: #include<bits/stdc++.h> using namespace std; int main(){ cout&l ...
- php 开启报错
// 开启报错提醒ini_set("display_errors", "On");error_reporting(E_ALL | E_STRICT); // 某 ...
- JVM类加载器的分类
类加载器的分类 JVM支持两种类型的类加载器,分别为引导类加载器(Bootstrap ClassLoader)和自定义类加载器(User-Defined ClassLoader). 从概念上来讲,自定 ...
- 基于深度学习的建筑能耗预测02——安装Tensorflow-gpu
一.检查显卡 ·查看自己的显卡配置是否能支持cuda,以及Tensorflow不同版本要求与CUDA及CUDNN版本对应关系: https://developer.nvidia.com/zh-cn/c ...
- android 使用SQLite的基本操作
Android操作数据库SQLite使用sql语句基本操作 1:自定义自己的SQLiteOpenHelper public class DBHelper extends SQLiteOpenHelpe ...
- Scala trait特质 深入理解
Scala trait特质 深入理解 初探Scala 特质trait 在Scala中,trait(特质)关键字有着举足轻重的作用.就像在Java中一样,我们只能在Scala中通过extends进行单一 ...
- 学校选址(ArcPy实现)
一.背景 合理的学校空间位置布局,有利于学生的上课与生活.学校的选址问题需要考虑地理位置.学生娱乐场所配套.与现有学校的距离间隔等因素,从总体上把握这些因素能够确定出适宜性比较好的学校选址区. 二.目 ...
- PAT (Basic Level) Practice (中文)1076 Wifi密码 (15分)
1076 Wifi密码 (15分) 下面是微博上流传的一张照片:"各位亲爱的同学们,鉴于大家有时需要使用 wifi,又怕耽误亲们的学习,现将 wifi 密码设置为下列数学题答案:A-1:B- ...
- centos7 配置ftp服务器搭建(匿名访问,以及本地登录)
大家好,今天来给大家分享一个基于centos 7的ftp服务器搭建 实现功能:匿名访问,本地登录 查看系统版本: [root@localhost ~]# cat /etc/redhat-release ...