P5853 [USACO19DEC] Tree Depth P

题目背景

For the new year, Farmer John decided to give his cows a festive binary search tree (BST)! To generate the BST, FJ starts with a permutation $a=\{a_1,a_2,\ldots,a_N\}$ of the integers $1\ldots N$, where $N\le 300$. He then runs the following pseudocode with arguments $1$ and $N.$ ``` generate(l,r): if l > r, return empty subtree; x = argmin_{l

题目描述

为了迎接新年,Farmer John 决定给他的奶牛们一个节日二叉搜索树! 为了生成这个二叉搜索树,Farmer John 从一个 $1 \dots N$ 的排列 $a= \{1,2, \dots ,N\}$ 开始,然后以参数 $l$ 和 $r$ 开始运行如下的伪代码: ``` generate(l,r): if l > r, return empty subtree; x = argmin_{l

输入格式

输出格式

说明/提示

#### 样例解释 1 对于这个样例,唯一满足条件的排列为 $a=\{1,2,3\}$。 #### 样例解释 2 对于这个样例,满足条件的两个排列分别为 $a=\{1,3,2\}$ 和 $a=\{2,1,3\}$。 #### 数据范围 对于全部数据,$1\le N\le 300$,$0\le K\le \frac{N(N-1)}{2}$,保证 $M$ 是一个 $\left[ 10^8,10^9+9 \right]$ 范围中的质数。 对于测试点 $3,4$,满足 $N \le 8$; 对于测试点 $5-7$,满足 $N \le 20$; 对于测试点 $8-10$,满足 $N \le 50$。 USACO 2019 December 铂金组T3