版本比较
USACO做题记录
正文
增加 11 行删除 11 行
133 行未改动全部展开13413513613713813813914014114236 行未改动17918018118218318318418518518618718718818918919019119219119219319419519619419519619719819920016 行未改动21721821922022122122222322422521 行未改动133 行未改动全部展开定义状态是 $dp_{n,k}$,表示有 $n$ 个节点,深度为 $k$ 的方案数。 我的状态和这个一样。
那么考虑去转移,设当前的左子树有 $x$ 个节点,则右子树有 $n-x+1$ 个节点
则有 $dp_{n,k}= \sum_{x=0}^{n} dp_{x,k-1} \times dp_{n-x-1,k-1} $ 则有 $dp_{n,k}= \sum_{x=0}^{n} dp_{x,k-1} \times dp_{n-x-1,k-1} $
考虑到有可能有些情况是转移不了的,就是无法用 $n$ 个结点拼 $k$ 层的情况(不够或超过)。实际上这些值会有贡献。
那么正确的状态设计其实是:有 $n$ 个结点时,深度不超过 $k$ 的方案数。36 行未改动
我在代码上注释写了一部分我的思路,后来又想到可以到这里写思路了。
A naive idea is that travel 1-inf by i
check if i is a humbel number
and count n numbers
in the worst case:
each element in S is discrete, so our plan will travel many uselees numbers
consider the construction assume we had constructed previous n-1 numbers
assume we had constructed previous n-1 numbers
the n-th number is : 1. new from set S and it has not been used , so a[n] = S[t] 2. construct from a[1 ~ n-1] , so a[n] = a[1 ~ n-1] * S[1 ~ t-1]
16 行未改动
#### [Stringsobits](https://usaco.training/usacoprob2?a=lVemSxElHGn&S=kimbits)看了很久不会做。看了题解没想到是个 dp
考虑递推,记 dp[i][j] 为 i 位二进制数中有 j 个 1 的数有多少个。 考虑递推,记 dp[i][j] 为 i 位二进制数中有 j 个 1 的数有多少个。
转移就考虑最高位是否放 1,dp[i][j] = dp[i-1][j] + dp[i-1][j-1]
考虑完方案数,那么第 m 小的数字的第 x 位 1 应该满足 m > dp[x][y]21 行未改动