给出标号为1到N的点,以及某些点最终的度数,允许在任意两点间连线,可产生多少棵度数满足要求的树?

第一行为N(0 < N < = 1000),接下来N行,第i+1行给出第i个节点的度数Di,如果对度数不要求,则输入-1

Prufer数列是无根树的一种数列。

在组合数学中,Prufer数列由有一个对于顶点标过号的树转化来的数列,点数为n的树转化来的Prufer数列长度为n-2。

树转Prufer:

  1. 找到编号最小的度数为11的点
  2. 删除该节点并在序列中添加与该节点相连的节点的编号
  3. 重复1,21,2操作,直到整棵树只剩下两个节点

  Prufer转树:

  1. 每次取出prufer序列中最前面的元素uu
  2. 在点集中找到编号最小的没有在prufer序列中出现的元素vv
  3. 给u,vu,v连边然后分别删除
  4. 最后在点集中剩下两个节点,给它们连边

性质:

  

       

   

#include <bits/stdc++.h>
using namespace std;
int d[];
struct bigint
{
int a[], len; bigint()
{
memset(a, , ), len = ;
} bigint operator* (const int &rhs) const
{
bigint ans;
ans.len = len + ;
for(int i = ; i <= len; ++i)
ans.a[i] += a[i] * rhs;
for(int i = ; i < ans.len; ++i)
if(ans.a[i] > )
{
ans.a[i + ] += ans.a[i] / ;
ans.a[i] %= ;
}
while(!ans.a[--ans.len]);
return ans;
} bigint operator/ (const int &rhs) const
{
bigint ans;
ans = *this, ++ans.len;
for(int i = ans.len; i; --i)
{
ans.a[i - ] += ans.a[i] % rhs * ;
ans.a[i] /= rhs;
}
while(!ans.a[--ans.len]);
return ans;
}
}; int main()
{
int n, sum = , cnt = ;
bigint ans;
scanf("%d", &n);
for(int i = ; i <= n; ++i)
{
scanf("%d", d + i);
if(!d[i])
{
puts("");
return ;
}
if(~d[i]) ++cnt, sum += d[i] - ;
}
if(sum > * n - )
{
puts("");
return ;
}
ans.a[] = ;
for(int i = n - - sum; i < n - ; ++i)
ans = ans * i;
for(int i = ; i <= n - - sum; ++i)
ans = ans * (n - cnt);
for(int i = ; i <= n; ++i)
for(int j = ; j <= d[i] - ; ++j)
ans = ans / j;
for(int i = ans.len; i; --i)
printf("%d", ans.a[i]);
puts("");
return ;
}

最新文章

  1. 解构C#游戏框架uFrame兼谈游戏架构设计
  2. IOS开发之application/x-www-form-urlencoded ;charset=utf-8
  3. DIOCP网络通讯流程
  4. ts tp 高清播放软件 Elecard MPEG Player 6.0.130827
  5. 一些Office 365的问题收集
  6. ajax请求超时时间
  7. 又一个提示框思密达,腾讯UED
  8. MSDN在线
  9. MongoDB 主从复制小实验
  10. 洛谷1439 排列LCS问题
  11. 嵌入式 linux 查看内存
  12. 关于通过addClass与removeClass用jquery控制有良好兼容的CSS3样式
  13. ffmpeg编译
  14. 【mongodb系统学习之九】mongodb保存数据
  15. IIS Express 域认证问题(https://stackoverflow.com/questions/4762538/iis-express-windows-authentication)
  16. C#中foreach命令的使用
  17. OpenCV3 for python3 学习笔记3-----用OpenCV3处理图像2
  18. RSA,JAVA私钥加密,C#公钥解密
  19. linq 获取列表最大值
  20. 深入分析Spring Boot2,解决 java.lang.ArrayStoreException异常

热门文章

  1. 酷Q插件_SDK———入门与使用
  2. go爬虫系列
  3. 修改umask后apache报错:because search permissions are missing on a component of the path,
  4. 性能排查--CPU占用高
  5. 老贾的幸福生活day6 整型和布尔值的转换 字符串讲解 for 循环简介
  6. 怎样在 Vue 中使用 事件修饰符 ?
  7. Java多线程(一):线程与进程
  8. string库
  9. Where is __dso_handle defined?
  10. 题解 P2859 【[USACO06FEB]摊位预订Stall Reservations】