博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5629 Clarke and tree dp+prufer序列
阅读量:4681 次
发布时间:2019-06-09

本文共 1590 字,大约阅读时间需要 5 分钟。

Clarke and tree

题目连接:

Description

Clarke is a patient with multiple personality disorder. One day, Clarke turned into a CS, did a research on data structure.

Now Clarke has n nodes, he knows the degree of each node no more than ai. He wants to know the number of ways to choose some nodes to compose to a tree of size s(1≤s≤n).

Input

The first line contains one integer T(1≤T≤10), the number of test cases.

For each test case:
The first line contains an integer n(2≤n≤50).
Then a new line follow with n numbers. The ith number ai(1≤ai<n) denotes the number that the degree of the ith node must no more than ai.

Output

For each test case, print a line with n integers. The ith number denotes the number of trees of size i modulo 109+7.

Sample Input

1

3
2 2 1

Sample Output

3 3 2

Hint:

At first we know the degree of node 1 can not more than 2, node 2 can not more than 2, node 3 can not more than 1. So

For the trees of size 1, we have tree ways to compose, are 1, 2 and 3. i.e. a tree with one node.
For the trees of size 2, we have tree ways to compose, are 1-2, 1-3, 2-3.
For the trees of size 3, we have two ways to compose, are 1-2-3, 2-1-3.

题意

给你n个点,每个点的度数最多为a[i]

然后分别问你点数为s的树,一共有多少种,(1<=s<=n)

题解:

考虑prufer的序列

对于点数为s,在这道题中z可以转化为这样:长度为s-2的序列里面,s个数都出现小于a[i]次的序列个数有多少个
我们直接n^4dp就好了
dp[i][j][k]表示考虑到了第i个数,我用了j,当前序列的长度为k的方案数

代码

#include
using namespace std;const int mod = 1e9+7;const int maxn = 62;long long dp[maxn][maxn][maxn];//考虑到了第i个点,现在出现了j个数,长度为k的方案数long long c[maxn][maxn];int a[maxn],n;void init(){ for(int i=0;i

转载于:https://www.cnblogs.com/qscqesze/p/5196324.html

你可能感兴趣的文章
android WIFI
查看>>
常用的匹配正则表达式和实例
查看>>
小组成员及其git链接
查看>>
SQL case when else
查看>>
MVc Identity登陆锁定
查看>>
cdn连接失败是什么意思_关于CDN的原理、术语和应用场景那些事
查看>>
ultraedit26 运行的是试用模式_免费试用U盘数据恢复工具 – 轻松找回U盘丢失的各种数据!...
查看>>
plsql 查询存储过程死锁语句_插入语句/存储过程死锁
查看>>
bootstrap table 收缩_bootstrap-table方法之:expandRow-collapseRow,展开或关闭当前行数据...
查看>>
jsp跳转到本身页面_五种JSP页面跳转方法详解
查看>>
mysql r_mysql:’r’是什么意思?
查看>>
无法加载 mysql 扩展_请检查您的 php 配置. - 文档_无法载入 mysql 扩展 请检查 PHP 配置...
查看>>
非空 默认 男 mysql_MySQL进阶13--常见六大约束: 非空/默认/主键/唯一约束/检查约束/外键约束--表级约束 / 列级约束...
查看>>
mysql错误修改数据_mysql数据修改问题
查看>>
navicat忘记mysql密码_navicat连接My SQL时忘记root密码处理方法
查看>>
mysql 左连接 左外连接吗_什么是左外连接?左外连接在工作表查询中的应用
查看>>
python sum函数导入list_python sum函数iterable参数为二维list,start参数为“[]”该如何理解...
查看>>
docker 删除多余镜像_多余Basedisk删除和vDisk镜像反转技术简介
查看>>
mysqlin会使用索引吗_被面试官虐了,索引为何使用B+树,你知道吗
查看>>
mysql8单节点500m_Kubernetes 部署 Mysql 8.0 数据库(单节点)
查看>>