Ignatius and the Princess III HDU - 1028

整数划分问题

假的dp(复杂度不对)

 #include<cstdio>
#include<cstring>
typedef long long LL;
LL ans[][];
LL n,anss;
LL get(LL x,LL y)
{
if(ans[x][y]!=-) return ans[x][y];
if(y==) return ans[x][y]=;
if(x<y) return ans[x][y]=;
ans[x][y]=;
LL i;
for(i=;i<=y;i++)
ans[x][y]+=get(x-y,i);
return ans[x][y];
}
int main()
{
memset(ans,-,sizeof(ans));
ans[][]=;
while(scanf("%lld",&n)==)
{
anss=;
for(int i=;i<=n;i++) anss+=get(n,i);
printf("%lld\n",anss);
}
return ;
}

一般的dp

ans[i][j]表示把i拆成最大j的数的方案数。要么分配一个j(剩下ans[i-j][j]),要么一个也不分配(剩下ans[i][j-1])。

参考

 #include<cstdio>
#include<cstring>
typedef long long LL;
LL ans[][];
LL n,anss;
LL get(LL x,LL y)
{
if(ans[x][y]!=) return ans[x][y];
if(y==) return ;
if(x<y) return ans[x][y]=get(x,x);
return ans[x][y]=get(x-y,y)+get(x,y-);
}
int main()
{
ans[][]=;
while(scanf("%lld",&n)==)
printf("%lld\n",get(n,n));
return ;
}

甚至可以写成这样

 #include<cstdio>
#include<cstring>
typedef long long LL;
LL ans[][];
LL n,anss;
LL get(LL x,LL y)
{
if(x<) return ;
if(ans[x][y]!=) return ans[x][y];
if(y==) return ;
return ans[x][y]=get(x-y,y)+get(x,y-);
}
int main()
{
ans[][]=;
while(scanf("%lld",&n)==)
printf("%lld\n",get(n,n));
return ;
}

母函数做法

参考

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
LL n;
LL ans[][];//ans[i][j]存的是到第i个多项式为止指数为j的项数
int main()
{
LL i,j,k;
while(scanf("%lld",&n)==)
{
memset(ans,,sizeof(ans));
ans[][]=;
for(i=;i<=n;i++)
for(j=;j<=n;j+=i)
for(k=;k<=n-j;k++)
ans[i][k+j]+=ans[i-][k];
printf("%lld\n",ans[n][n]);
}
return ;
}

Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数的更多相关文章

  1. Ignatius and the Princess III HDU - 1028 -生成函数or完全背包计数

    HDU - 1028 step 1:初始化第一个多项式 也就是 由 1的各种方案 组 成 的多项式 初始化系数为 1.临时区 temp初始化 为 0 step 2:遍历后续的n - 1 个 多项式 , ...

  2. Ignatius and the Princess III HDU - 1028

    题目传送门:https://vjudge.net/problem/HDU-1028 思路:整数拆分构造母函数的模板题 1 //#include<bits/stdc++.h> 2 #incl ...

  3. HDU 1028 整数拆分问题 Ignatius and the Princess III

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  4. HDU 1028 整数拆分 HDU 2082 找单词 母函数

    生成函数(母函数) 母函数又称生成函数.定义是给出序列:a0,a1,a2,...ak,...an, 那么函数G(x)=a0+a1*x+a2*x2+....+ak*xk +...+an* xn  称为序 ...

  5. hdu,1028,整数拆分的理解

    #include"iostream"using namespace std;int main() { int n,i,j,k; int c[122],temp[122]; //c[ ...

  6. 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 ...

  7. hdu acm 1028 数字拆分Ignatius and the Princess III

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  8. hdu 1028 Ignatius and the Princess III 简单dp

    题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...

  9. hdu 1028 Ignatius and the Princess III 母函数

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

随机推荐

  1. pycharm查看代码注释的方法,代码编写日志及作者信息等

    竟然在边栏有个右键的快捷键.annotate可以查看代码书写日期及作者 鼠标悬停可以看到更加详细的时间等信息 原理应该是利用git blame

  2. USB多重系統 - 開機碟工具 – WinSetupFromUSB

    WinSetupFromUSB下載與安裝 讓USB磁碟擁有多重開機的功能,WinSetupFromUSB有著提軟體和硬體的高相容性. [官方網頁]:http://www.winsetupfromusb ...

  3. oracle统计信息

    手工刷ORACLE统计信息  select count(1) from LOG_TRX_DETAIL;  select * from user_tab_statistics where table_n ...

  4. 编程基础知识——Java JNI开发流程(2)

    android中使用jni调用本地C++库 android平台上的本地库文件后缀 .so.类似windows上的dll文件. 要在android上使用jni.首先须要下载android ndk. 操作 ...

  5. Input系统—ANR原理分析(转)

    一. 概述 当input事件处理得慢就会触发ANR,那ANR内部原理是什么,哪些场景会产生ANR呢. “工欲善其事必先利其器”,为了理解input ANR原理,前面几篇文章疏通了整个input框架的处 ...

  6. bufferevent 与 socket

    http://blog.sina.com.cn/s/blog_56dee71a0100qx4s.html 很多时候,除了响应事件之外,应用还希望做一定的数据缓冲.比如说,写入数据的时候,通常的运行模式 ...

  7. Essay

    要养成先连续输入一对匹配的字符——比如"("和")",以及"{"和"}"——再在其中填写内容的习惯.如果先填写内容,很容 ...

  8. Intel为Google的物联网平台Brillo推出开发板Edison

    Brillo* is a solution from Google* for building connected devices. Incorporating aspects of the Andr ...

  9. python iterable 和list、dictionary的区别和联系

    1 为什么一些函数的参数指定要iterable object的,但是也可以传入list为参数? 因为list.dictionary都是iterable object. 在iterable object ...

  10. Object Query Language (OQL) query 基本使用

    OQL是对java堆内存进行查询分析 使用方法: 1.查看java线程id jps -lvm 上图红框中的为pid: 2.运行命令-导出堆内存信息-会生成一份文件在你本地 jmap -dump:liv ...