树的计数 bzoj-1211 HNOI-2004

题目大意题目链接

注释:略。


想法

prufer序列有一个性质就是一个数在prufer序列中出现的次数等于这个prufer序列生成的树中它的度数-1。

故此我们就是要求$C_{n-2}^{d_1-1}\times C_{n-2-d_1+1}^{d_2-1}\times \cdots \times C_{d_n-1}^{d_n-1}$。

随便搞搞就行了。

Code:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define M 160
using namespace std;
typedef long long ll;
int n,sum,d[M];
int cnt[M];
ll ans=1;
ll Quick_Power(ll x,int y)
{
ll re=1;
while(y)
{
if(y&1)re*=x;
x*=x;
y>>=1;
}
return re;
}
void Decomposition(int x,int flag)
{
int i;
for(i=2;i*i<=x;i++)
while(x%i==0)
cnt[i]+=flag,x/=i;
if(x^1)
cnt[x]+=flag;
}
int main()
{
int i,j;
cin>>n;
for(i=2;i<=n-2;i++)
Decomposition(i,1);
for(i=1;i<=n;i++)
{
scanf("%d",&d[i]);
if(!d[i]&&n!=1)
{
puts("0");
return 0;
}
sum+=d[i]-1;
for(j=2;j<=d[i]-1;j++)
Decomposition(j,-1);
}
if(sum!=n-2)
{
puts("0");
return 0;
}
for(i=1;i<=n-2;i++)
if(cnt[i])
ans*=Quick_Power(i,cnt[i]);
cout<<ans<<endl;
}

小结:prufer序列好像只有裸题诶.....

最新文章

  1. PO VO BO DTO POJO DAO(转)
  2. XUtils3 的 环境搭建
  3. 用SQL语句获得一个存储过程返回的表
  4. PHP中include和require(转)
  5. [LintCode] Median of Two Sorted Arrays 两个有序数组的中位数
  6. FreeBSD打开DTrace支持
  7. UICollectionView移动
  8. Python python 基本语法
  9. 基于 Equinox 的 OSGi Console 的研究和探索
  10. linux下进入root
  11. java程序执行时,JVM内存
  12. 【贪心】 poj 1032 和为n的若干数最大乘积
  13. 2.SQL语言进阶
  14. asp.net core 系列 7 Razor框架路由(上)
  15. Linux内核第四节 20135332武西垚
  16. [dpdk] dpdk多线程任务调度
  17. docker下搭建fastfds集群版
  18. 深入理解hello world
  19. 学习dbms_parallel_execute包
  20. 关闭Windows Server 2012的IE增强安全配置

热门文章

  1. hihocoder offer收割编程练习赛11 B 物品价值
  2. sh/bash/csh/Tcsh/ksh/pdksh等shell本质区别
  3. 微信小程序之多行文本省略号
  4. R Programming week1-Data Type
  5. YOLO模型对图片中车辆的识别比对
  6. 解决jquery与其他库的冲突
  7. Vue 路由知识二(工程模式下路由的配置)
  8. HDU_1710_二叉树前序中序确定后序
  9. C# html table转excel
  10. 第1节 hive安装:2、3、4、5、(多看几遍)