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 ...
随机推荐
- JDK7的maven项目切换到JDK8全纪录
今天花了一个下午的时间,将一个之前用JDK7写的web项目升级到了JDK8,这个过程中遇到了许多麻烦,在这里简单的记录一下,方便日后查看. 1.下载JDK8并且配置,这个我就不说了,反正大家都知道,需 ...
- 如何用DW设计界面 结合 VS设计后台代码
原文发布时间为:2008-11-02 -- 来源于本人的百度文章 [由搬家工具导入] 问:在vs.net里有form标记,而dw里却没有,两个里面的标记代码都不一样,怎么能通用? 在.net里修改dw ...
- ADO:DataSet合并两张表( ds.Merge(ds1))
原文发布时间为:2008-08-01 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...
- git超详细教程【转】
转自:http://blog.csdn.net/liuwengai/article/details/52072344 GitHub操作总结 : 总结看不明白就看下面的详细讲解. GitHub操作流 ...
- 标准C程序设计七---35
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- php接口开发时,数据解析失败问题,字符转义,编码问题
php接口开发时,数据解析失败问题,字符转义,编码问题 情景: A平台--->向接口请求数据---->接口向B平台请求数据---->B平台返回数据给接口---->接口返回数据给 ...
- hdu 1099(数学)
Lottery Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- python常用模块2
collections模块 在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter.deque.defaultdict. ...
- ubuntu下某些文件目录
1.#include <stdio.h> 2.#include <stdlib.h> stdio.h和stdlib.h的路径:/usr/include
- 某考试 T3 sine
推完一波式子之后发现是个矩阵23333. 其实只要发现是矩阵之后就是个水题了. #include<bits/stdc++.h> #define ll long long using nam ...