[codeforces830D]Singer House
来源:互联网 发布:长兴法院拍卖淘宝网 编辑:程序博客网 时间:2024/05/16 13:53
题目大意
给定n,现有深度为n的满二叉树,对于一个节点,给它与它的所有父亲连一条边。
问:得到的新的图有多少条不同的简单路径(1->2和2->1算不同路径)答案模1,000,000,007
n≤400
分析
关键在于如何设好状态
设f[i][j]表示深度为i的满二叉树中,存在j条路径的方案数。可以枚举i,然后枚举两棵子树大小,然后分类讨论转移(讨论时注意细节,比如路径的方向)。
第二维可能会很大。注意到合并两条路径需要用到它们的一个祖先。所以有用的状态的第二维规模不超过n,所以第二维也是n级别的。
时间复杂度
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N=405,mo=1e9+7,Inv=500000004;typedef long long LL;int n,f[N][N],g[N],ans;int main(){ scanf("%d",&n); f[1][0]=f[1][1]=1; for (int i=1;i<=n;i++) g[i]=(LL)i*(i-1)%mo; for (int i=2;i<=n;i++) { for (int j=0;j<=n;j++) { for (int k=0;k<=n-j;k++) { int t=(LL)f[i-1][j]*f[i-1][k]%mo; f[i][j+k]=(f[i][j+k]+(LL)t*((j+k)*2+1))%mo; f[i][j+k-1]=(f[i][j+k-1]+(LL)t*g[j+k])%mo; f[i][j+k+1]=(f[i][j+k+1]+t)%mo; } } } ans=f[n][1]; printf("%d\n",ans); return 0;}
阅读全文
0 0
- [codeforces830D]Singer House
- [DP][打表] Codeforces Round #424 .D Singer House
- VK cup 2017 E. Singer House (奇妙的dp)
- Codeforces-830D Singer House(组合数+dp)
- Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) D. Singer House(dp)
- The Singer
- 小众歌手 niche singer
- house
- house
- house
- house
- Words Singer 0.1 (C#开源)
- Devu, the Singer and Churu, the Joker
- iOS App Singer 重签名工具
- Codeforces 439A Devu, the Singer and Churu, the Joker
- A. Devu, the Singer and Churu, the Joker
- Codeforces 439A, the Singer and Churu, the Joker(水题)
- Codeforces 439 A. Devu, the Singer and Churu, the Joker
- flex的应用
- 初入前端,学习进程
- 三、梯度下降与反向传播(含过程推导及证明)
- Numpy(四)
- display: none;与visibility: hidden;的区别
- [codeforces830D]Singer House
- Ubuntu 16.04 LTS安装sogou输入法详解
- oracle列转行,分割逗号,成一个张表
- 面试题2:实现Singleton模式
- BOOST库 之 lexical_cast类型转换
- linux系统排错
- 并发容器
- mybatis与hibernate的不同
- 8.9例题