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 ...
随机推荐
- linux下安装firefox
首先检查系统有没有安装:rpm -qa|grep firefox 如果有安装,先删掉rpm -e * firefox不同版本下载:http://liulanmi.com/firefox 具体方法如下: ...
- Bzoj2038 小Z的袜子(hose)
Time Limit: 20000MS Memory Limit: 265216KB 64bit IO Format: %lld & %llu Description 作为一个生活散漫 ...
- WebRTC VideoEngine综合应用示例(一)——视频通话的基本流程(转)
本系列目前共三篇文章,后续还会更新 WebRTC VideoEngine综合应用示例(一)——视频通话的基本流程 WebRTC VideoEngine综合应用示例(二)——集成OPENH264编解码器 ...
- 2016-2017 ACM-ICPC, South Pacific Regional Contest (SPPC 16)
题目链接 Codeforces_Gym_101177 Problem A Anticlockwise Motion 直接模拟即可 #include<iostream> #include ...
- ubuntu系统克隆
使用clonezilla,原文地址:http://www.linuxidc.com/Linux/2014-09/107117.htm 类似的一篇:http://storysky.blog.51cto. ...
- Ext.Ajax.request批量提交表单
介绍一下批量提交grid中数据的问题 js文件中的提交方法如下: listeners: { click: function btnClick(button) { var win = button.up ...
- Maven配置tomcat和jetty插件来运行项目
针对eclipse中的Run on Server有些情况下并不是那么好操作,比如配置maven下的springmvc插件,如果使用此方法运行会很容易出现组件缺少导致错误出现一大堆的问题. 那么针对这种 ...
- 【IntelliJ idea/My/ecplise】启动项目前,修改配置JVM参数
My/ecplise下都是一样的: IDEA下:
- Android学习笔记(35):Android活动条
在Android3.0之后,Google对UI导航设计上进行了一系列的改革,当中有一个很好用的新功能就是引入的ActionBar,用于代替3.0之前的标题栏,并提供更为丰富的导航效果. ActionB ...
- CSRF攻击 & XSS攻击
之前有几篇文章写了 SQL注入类问题: http://www.cnblogs.com/charlesblc/p/5987951.html (介绍) http://www.cnblogs.com/cha ...