ACdream 1412 DP+排列组合
2-3 Trees
Problem Description
2-3 tree is an elegant data structure invented by John Hopcroft. It is designed to implement the same functionality as the binary search tree. 2-3 tree is an ordered rooted tree with the following properties:
- the root and each internal vertex have either 2 or 3 children;
- the distance from the root to any leaf of the tree is the same.
The only exception is the tree that contains exactly one vertex — in this case the root of the tree is the only vertex, and it is simultaneously a leaf, i.e. has no children. The main idea of the described properties is that the tree with l leaves has the height O(log l).
Given the number of leaves l there can be several valid 2-3 trees that have l leaves. For example, the picture below shows the two possible 2-3 trees with exactly 6 leaves.

Given l find the number of different 2-3 trees that have l leaves. Since this number can be quite large, output it modulo r.
Input
Output
Sample Input
6 1000000000
7 1000000000
Sample Output
2
3
Source
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
const int N=4e5+,mods=,inf=2e9+; int n,mod,c[][];
LL dp[N];
int main() {
while(scanf("%d%d",&n,&mod)!=EOF) {
for(int i = ; i <= ; ++i) {
c[i][] = ;
for(int j = ; j <= i; ++j) {
c[i][j] = (c[i-][j] + c[i-][j-])%mod;
}
}
memset(dp,,sizeof(dp));
dp[] = ;
for(int i = ; i <= n; ++i) {
for(int j = ; j <= i; ++j) {
if(j* + (i-j)* <= )
dp[j* + (i-j)*] += dp[i]*c[i][j],
dp[j* + (i-j)*]%=mod;
}
}
printf("%lld\n",dp[n]%mod);
}
return ;
}
ACdream 1412 DP+排列组合的更多相关文章
- 【BZOJ】2111: [ZJOI2010]Perm 排列计数 计数DP+排列组合+lucas
[题目]BZOJ 2111 [题意]求有多少1~n的排列,满足\(A_i>A_{\frac{i}{2}}\),输出对p取模的结果.\(n \leq 10^6,p \leq 10^9\),p是素数 ...
- 【BZOJ】4559: [JLoi2016]成绩比较 计数DP+排列组合+拉格朗日插值
[题意]n位同学(其中一位是B神),m门必修课,每门必修课的分数是[1,Ui].B神碾压了k位同学(所有课分数<=B神),且第x门课有rx-1位同学的分数高于B神,求满足条件的分数情况数.当有一 ...
- G.subsequence 1(dp + 排列组合)
subsequence 1 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 You are ...
- LightOJ1005 Rooks(DP/排列组合)
题目是在n*n的棋盘上放k个车使其不互相攻击的方案数. 首先可以明确的是n*n最多只能合法地放n个车,即每一行都指派一个列去放车. dp[i][j]表示棋盘前i行总共放了j个车的方案数 dp[0][0 ...
- HDU 5816 状压DP&排列组合
---恢复内容开始--- Hearthstone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java ...
- bzoj 3398 [Usaco2009 Feb]Bullcow 牡牛和牝牛——前缀和优化dp / 排列组合
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3398 好简单呀.而且是自己想出来的. dp[ i ]表示最后一个牡牛在 i 的方案数. 当前 ...
- 【noi 2.6_9288】&【hdu 1133】Buy the Ticket(DP / 排列组合 Catalan+高精度除法)
题意:有m个人有一张50元的纸币,n个人有一张100元的纸币.他们要在一个原始存金为0元的售票处买一张50元的票,问一共有几种方案数. 解法:(学习了他人的推导后~) 1.Catalan数的应用7的变 ...
- acdream 1412 2-3Trees (组合+DP)
题意:2-3树的每个结点(除了叶子外)有2或3个孩子(分支),假设是一个满2-3树,那么给出叶子的数量,求这样的树有多少棵.(注:有2个孩子的结点视为相同,有3个孩子的结点视为相同,比如倒数第2层有4 ...
- 【BZOJ-1974】auction代码拍卖会 DP + 排列组合
1974: [Sdoi2010]auction 代码拍卖会 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 305 Solved: 122[Submit ...
随机推荐
- oracle分析函数之ratio_to_report
ratio_to_report主要完成对百分比的计算,语法为ratio_to_report(exp) over()也就是根据over窗口函数的作用区间,求出作用区间中的单个值在整个区间的总值的比重比如 ...
- git命令初级
git是开源的分布式版本控制系统,分布式主要区别于集中式代表CVS(Concurrent Version System,遵从C/S架构,同步比较笨拙.)和SVN(Subversion),linux开发 ...
- Python之面向对象slots与迭代器协议
Python之面向对象slots与迭代器协议 slots: # class People: # x=1 # def __init__(self,name): # self.name=name # de ...
- <struct、union、enum>差异
关于C++和C的区别 区别最大的是struct,C++中的struct几乎和class一样了,可以有成员函数,而C中的struct只能包含成员变量. enum,union没区别. struct的定义 ...
- clip-path实现loading圆饼旋转效果以及其他方法
一.loading效果 二.clip-path css中的剪切clip-path属性是CSS Masking模块的一部分. 矩形 clip-path:inset(top right bottom le ...
- python 爬虫示例,方便日后参考
参考网址:https://zhuanlan.zhihu.com/p/32037625 def getOneMoviesInfo(Mid,url): import requests from lxml ...
- java读utf8 的txt文件,第一个字符为空或问号问题
参考:https://blog.csdn.net/yangzhichao888/article/details/79529756 https://blog.csdn.net/wangzhi291/ar ...
- JavaEE JDBC 核心API
JDBC接口核心的API @author ixenos java.sql.* 和 javax.sql.* |- Driver接口: 表示java驱动程序接口.所有的具体的数据库厂商要来实现此接口 ...
- Maven 引入外部包
当需要从外部引入一个包(譬如说读写Excel 的POI jar 包 ), 不需要手动地去官网下载一个包然后粘贴到相应的地方. 只需要把Java 工程 转为 Maven 工程 ( 在工程上右键 > ...
- 洛谷 通天系列 P1760 P1757 P1759
P1760 通天之汉诺塔 汉诺塔问题.一个高精乘单精解决 ans=2^n-1 /*by SilverN*/ #include<algorithm> #include<iostream ...