HDU1294 Rooted Trees Problem(整数划分 组合数学 DP)
讲解见http://www.cnblogs.com/IMGavin/p/5621370.html, 4 可重组合
dfs枚举子树的节点个数,相乘再累加
1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<cstdlib>
5 #include<algorithm>
6 using namespace std;
7 typedef long long LL;
8
9 LL f[];
LL cm(LL n, LL m){
m = min(n - m, m);
LL ans = ;
for(LL i = ; i <= m; i++){
ans = ans * (n - m + i) / i;
}
return ans;
}
void dfs(int n, int x, int r, LL mul){
if(r == ){
f[n] += mul;
}else{
for(int i = x; i < n; i++){
for(int j = ; i * j <= r; j++){
dfs(n, i + , r - i * j, mul * cm(f[i] + j - ,j ) );
}
}
}
}
int main(){
memset(f, , sizeof(f));
f[] = ;f[] = ;
for(int i = ; i <= ; i++){
dfs(i, , i - ,);
}
int n;
while(~scanf("%d", &n)){
printf("%I64d\n", f[n]);
}
return ;
46 }
HDU1294 Rooted Trees Problem(整数划分 组合数学 DP)的更多相关文章
- HDU p1294 Rooted Trees Problem 解题报告
http://www.cnblogs.com/keam37/p/3639294.html keam所有 转载请注明出处 Problem Description Give you two definit ...
- 51nod 1201 整数划分 基础DP
1201 整数划分 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 关注 将N分为若干个不同整数的和,有多少种不同的划分方式,例如:n = 6,{6} ...
- SDUT3146:Integer division 2(整数划分区间dp)
题目:传送门 题目描述 This is a very simple problem, just like previous one. You are given a postive integer n ...
- 整数划分——区间dp(石子合并)
这不是将一个数以一来划分,而是把一个整数以位来划分 题目描述 如何把一个正整数N(N长度<20)划分为M(M>1)个部分,使这M个部分的乘积最大.N.M从键盘输入,输出最大值及一种划分方式 ...
- 51Nod 1201 整数划分 (经典dp)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1201 题意不多说了. dp[i][j]表示i这个数划分成j个数 ...
- HDU 1294 Rooted Trees Problem
题目大意:求有n个节点的树有几种? 题解:http://www.cnblogs.com/keam37/p/3639294.html #include <iostream> typedef ...
- bzoj 3612 [Heoi2014]平衡——整数划分(dp)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3612 因为力矩的缘故,变成了整数划分. 学习到了整数划分.就是那个图一样的套路.https: ...
- 整数划分 (区间DP)
整数划分(四) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 暑假来了,hrdv 又要留学校在参加ACM集训了,集训的生活非常Happy(ps:你懂得),可是他最近 ...
- 51nod 1201 整数划分 dp
1201 整数划分 基准时间限制:1 秒 空间限制:131072 KB 收藏 关注 将N分为若干个不同整数的和,有多少种不同的划分方式,例如:n = 6,{6} {1,5} {2,4} {1,2 ...
随机推荐
- java中类名,方法,变量,包名等大小写命名规范
类名:首字母大写,其他单词中首字母大写,其他小写方法名:首字母小写,其他单词中首字母大写,其他小写变量:与方法名规则同包名:全部小写接口interface:I开头
- 深入浅出Mybatis-与Spring集成
单独使用mybatis是有很多限制的(比如无法实现跨越多个session的事务),而且很多业务系统本来就是使用spring来管理的事务,因此mybatis最好与spring集成起来使用. 前置要求 版 ...
- js手机网页跳转
在网页头部加入如下代码: <script type="text/javascript"> function browserRedirect() { var sUserA ...
- C#读写SQL Server数据库图片
效果图: 下载链接: http://download.csdn.net/detail/u010312811/9492402 1.创建一个Winform窗体,窗体分为“数据上传”和“数据读取”两部分: ...
- struts2 学习路线
1.请求:开发struts2流程,(常见配置.action的方法的访问.ServletApi的访问.结果页面类型) 2.强求:封装参数.类型转换.数据校验.国际化.拦截器. 3.响应页面的生成:文件上 ...
- yum install 安装时报yum doesn't have enough cached data to continue.
yum install 安装时报yum doesn't have enough cached data to continue. 安装epel,yum -y install epel-release后 ...
- MySQL binlog 组提交与 XA(分布式事务、两阶段提交)【转】
概念: XA(分布式事务)规范主要定义了(全局)事务管理器(TM: Transaction Manager)和(局部)资源管理器(RM: Resource Manager)之间的接口.XA为了实现分布 ...
- glib-2.49.4-msys-x86-staticLib.7z
glib-2.49.4 MSYS 静态库 编译 export LIBFFI_CFLAGS=" -I/usr/local/lib/libffi-3.2.1/include " \ e ...
- Java for LeetCode 222 Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...
- 【leetcode】Number of 1 Bits (easy)
做太多遍了,秒杀. class Solution { public: int hammingWeight(uint32_t n) { ; ), num++); return num; } };