hdu1028(母函数+DP)
题目信息:求分解整数n的个数q(n);能够母函数或者DP
http://acm.hdu.edu.cn/showproblem.php?pid=1028
AC代码:
/******************************
题目大意:求分解整数n的个数q(n)
例:
5 = 5;
5 = 4 + 1;
5 = 3 + 1 + 1;
5 = 3 + 2;
5 = 2 + 2 + 1;
5 = 2 + 1 + 1 + 1;
5 = 1 + 1 + 1 + 1 + 1;
sum(5) = 7;不区分顺序,
(3+2)与(2+3)为同一个
*******************************/
/**
*DP
*/
#include<iostream>
using namespace std;
int a[121][121];//储存数组
long long q(int n,int m)
{//递归分析,m为分解的最大值
if((n<1)||(m<1)) return 0;
if((n==1)||(m==1)) return 1;
if(n<m) return q(n,n);
if(n==m) return q(n,m-1)+1;
return q(n,m-1)+q(n-m,m);
}
/**
int main()
{
for(int i=1;i<=120;i++){
for(int j=1;j<=120;j++){//由递归式转存到数组中。降低计算量
if((i==1)||(j==1)) a[i][j]=1;
else if(i<j) a[i][j]=a[i][i];
else if(i==j) a[i][j]=a[i][j-1]+1;
else a[i][j]=a[i][j-1]+a[i-j][j];
}
}
int n;
while(cin>>n){
cout<<a[n][n]<<endl;
}
return 0;
}**/
/**
*母函数解法
*/
int main()
{
int a[350],b[350],i,j,k,n;
while(cin>>n&&n)
{
for(i=0;i<=n;i++){
a[i]=1;
b[i]=0;
}
for(i=2;i<=n;i++){
for(j=0;j<=n;j++)
for(k=0;k+j<=n;k+=i)
b[k+j]+=a[j];
for(j=0;j<=n;j++){
a[j]=b[j];
b[j]=0;
}
}
cout<<a[n]<<endl;
}
return 0;
}
hdu1028(母函数+DP)的更多相关文章
- hdu刷题2
hdu1021 给n,看费波纳列数能否被3整除 算是找规律吧,以后碰到这种题就打打表找找规律吧 #include <stdio.h> int main(void) { int n; whi ...
- HDU 1398 Square Coins(母函数或dp)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDU 1028 Ignatius and the Princess III:dp or 母函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 题意: 给你一个正整数n,将n拆分成若干个正整数之和,问你有多少种方案. 注:"4 = ...
- hdu 1284 钱币兑换问题 (递推 || DP || 母函数)
钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- E比昨天更多的棒棒糖(Easy+Hrad)(华师网络赛)(DP||母函数||背包优化)
Time limit per test: 2.0 seconds Memory limit: 512 megabytes 唐纳德先生的某女性朋友最近与唐纳德先生同居.该女性朋友携带一 baby.该 b ...
- HihoCoder1339 Dice Possibility(概率DP+母函数)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 What is possibility of rolling N dice and the sum of the numb ...
- 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 1398 Square Coins(母函数或dp)
Problem Description People in Silverland use square coins. Not only they have square shapes but also ...
- 题解报告:hdu 1028 Ignatius and the Princess III(母函数or计数DP)
Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...
随机推荐
- (超详细)使用git命令行将本地仓库代码上传到github或gitlab远程仓库
(超详细)使用git命令行将本地仓库代码上传到github或gitlab远程仓库 本地创建了一个 xcode 工程项目,现通过 命令行 将该项目上传到 github 或者 gitlab 远程仓库,具体 ...
- POJ 3037 Skiing
Skiing Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4810 Accepted: 1287 Special ...
- c#.net分类上升达人~~~呵呵。。。
原文发布时间为:2008-11-11 -- 来源于本人的百度文章 [由搬家工具导入] 觉得自己蛮无聊的~~~~~~~~~(>_<)~~~~
- 不需 porting 就可充電的 charger ic。
Origin : 今天同事問我一個關於配有 RT9458 charger ic 的手機的問題, 這手機可能要送到廠商那, 需要 porting charger ic, 看了一下,跟他說這個充電部份不需 ...
- LeetCode OJ--Single Number
https://oj.leetcode.com/problems/single-number/ 给一个数列,其中只有一个数不是两两相同的,在O(n)时间内求出来,并且不使用额外空间. 使用异或操作,如 ...
- awk 统计
命令太多,记不住,组合起来用一把…..示例文件: 1 2 3 4 5 6 7 8 9 10 11 [root@lovedan test]# cat a.txt hello good world hel ...
- Noip2016题解&总结
原文放在我的uoj博客上,既然新开了blog,那就移过来了 玩具谜题(toy) 送分题.没有什么好说的. 直接按照题目的要求模拟即可. 标准的noip式day1T1. #include<cstd ...
- JDK1.8中的Lambda表达式和Stream
1.lambda表达式 Java8最值得学习的特性就是Lambda表达式和Stream API,如果有python或者javascript的语言基础,对理解Lambda表达式有很大帮助,因为Java正 ...
- Maven插件maven-antrun-plugin的使用
以下引用官方的介绍http://maven.apache.org/plugins/maven-antrun-plugin/: 一.什么是maven-antrun-plugin? 该插件提供从Maven ...
- 【jQuery】方法和选择器的双重使用详解
1.jQuery选择直接子节点+除了某个元素 1>方法 $(".begon").children(".row:not(.moreDetail)") 2&g ...