[bzo1211][HNOI2004]树的计数_prufer序列
2024-08-30 06:51:45
树的计数 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序列好像只有裸题诶.....
最新文章
- PO VO BO DTO POJO DAO(转)
- XUtils3 的 环境搭建
- 用SQL语句获得一个存储过程返回的表
- PHP中include和require(转)
- [LintCode] Median of Two Sorted Arrays 两个有序数组的中位数
- FreeBSD打开DTrace支持
- UICollectionView移动
- Python python 基本语法
- 基于 Equinox 的 OSGi Console 的研究和探索
- linux下进入root
- java程序执行时,JVM内存
- 【贪心】 poj 1032 和为n的若干数最大乘积
- 2.SQL语言进阶
- asp.net core 系列 7 Razor框架路由(上)
- Linux内核第四节 20135332武西垚
- [dpdk] dpdk多线程任务调度
- docker下搭建fastfds集群版
- 深入理解hello world
- 学习dbms_parallel_execute包
- 关闭Windows Server 2012的IE增强安全配置