CSU 2259 King's Colors 二项式反演

http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2259

Description

Far, far away, there is the mystical Kingdom of Trees (more formally, "Royal Commonwealth of Connected Undirected Simple Acyclic Graphs"). The King there is very sad because his kingdom is not accepted as a sovereign state in the United Nations. In order to become a member, he needs to make a flag the UN can put on their website.

The flag will of course consist of the King's favorite tree, which contains n nodes. The King would be happy to just have the tree colored in black and white, but for the sake of his wife the Queen, he decided that the tree will contain all the favorite colors of their k children (they all have distinct favorite colors). Clearly, no two neighboring nodes can have the same color, but otherwise any coloring of the tree using exactly the k colors would make a feasible flag candidate.

How many different flags are possible?

Input

The first line contains two integers n and k (2 ≤ k ≤ n ≤ 2 500), where n is the number of nodes in the King's favorite tree and k is the number of children. Then follow n − 1 lines describing the edges in the tree; the i'th of these lines contains a non-negative integer pi < i, meaning that node pi is the parent of i.

The nodes are numbered from 0 to n − 1 and the tree is rooted at node 0. Note that the embedding of the tree on the flag is already fixed, the only thing that remains is to assign colors.

Output

Output the number of different possible color assignments. The number can be quite big, so the King has requested to know the answer modulo 1 000 000 007​.

Sample Input

4 3
0
1
1
-----------------------
6 4
0
1
1
3
4

Sample Output

18
----------------------
600

Hint

Source

ncpc2018

题目大意:给一颗有n个节点的数用k种颜色染色,要求任意两个相邻节点的颜色不同且恰好使用了k种颜色,问有多少种方案数?

思路:二项式反演。设Fi为最多使用了i种颜色染色的方案数,Ti为恰好使用了i种颜色染色的方案数,由组合数学知识可得:

F_{k}=\sum_{i=0}^{k}C_{k}^{i}*T_{i},那么由二项式反演可得:T_{k}=\sum_{i=0}^{k}(-1)^{k-i}*C_{k}^{i}*F_{i},因此只要我们知道了Fi的值,就可以累加得到Tk也即答案的值。考虑Fi的意义:在树上染色使相邻节点的颜色不同,那么只要使节点与其父节点(如果存在的话)的颜色不同即可,因此F_{i}=i*(i-1)^{n-1}。组合数也很好算,利用公式C_{n}^{m}=C_{n-1}^{m-1}+C_{n-1}^{m}即可。

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;

ll C[2505][2505];//组合数
ll f[2505];
ll xs[2505];
ll n,k;
const ll MOD=1e9+7;

ll pow(ll a,ll b)
{
	ll t1=1,t2=a;
	while(b)
	{
		if(b&1)
			t1=(t1*t2)%MOD;
		t2=(t2*t2)%MOD;
		b>>=1;
	}
	return t1;
}

void init()
{
	for(ll i=0;i<=k;i++)
	{
		f[i]=(i*pow(i-1,n-1))%MOD;
		C[i][i]=C[i][0]=1;
		if((k-i)&1)
			xs[i]=-1;
		else
			xs[i]=1;
		for(int j=1;j<i;j++)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;
	}
}

int main()
{
	scanf("%lld %lld",&n,&k);
	int t;
	for(int i=1;i<n;i++)
		scanf("%d",&t);
	init();
	ll ans=0;
	for(int i=0;i<=k;i++)
		ans=(ans+(xs[i]*C[k][i]*f[i])%MOD+MOD)%MOD;
	printf("%lld\n",ans);
	return 0;
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: CSU飞跃手册2019是一个以服务学生发展为宗旨的学生服务项目,帮助学生实现个人成长和职业发展目标。飞跃手册提供了诸如成功学、职业规划、就业技巧以及个人发展等方面的指导,帮助学生掌握自我认知、提升职场竞争力并构建良好的人脉关系。 飞跃手册2019包括三个模块。第一个模块着重讲解如何探索自我,明确职业目标和规划职业道路。这些关键的步骤帮助学生发现自己的职业特长和兴趣爱好,从而为个人职业发展做出决策和规划。 第二个模块提供了职业发展过程中的必备技能,如招聘面试技巧、简历写作、职场沟通、决策和问题解决能力,以及管理和领导力等。这些技能帮助学生在职场中不断学习和成长,并展示自己的优势。 第三个模块则介绍如何利用社会资源和人脉关系来推动个人职业发展。它包括了网络管理、人脉建立、社交礼仪和社会责任等方面的指导。 总之,CSU飞跃手册2019是一份应对职场挑战和工作生涯的指南, 帮助学生建立自己的职业目标并实现自我发展。它讲解了个人成长、职场技能、人脉力量和社会责任等方面的内容,为学生的成功创造了一个强有力的支撑体系。 ### 回答2: CSU飞跃手册2019是一本由中国海洋大学控制科学与工程学院发行的指导学生爆炸性训练和实习的手册。该手册将学生分为不同职业兴趣组,并提供了具体的介绍、岗位培训以及实习就业方案。 该手册还包括了部分参考书目、学术论文和个人成长方向的建议,在实习期间指导学生更好地发展个人能力和提高自己的竞争力。除此之外,该手册还有一些校内外的实践活动介绍和经验分享。这些活动涵盖了多个不同领域,包括科技、创业、环保和社会公益等。 该手册还提供了一些面试技巧和求职指南,帮助学生更好地应对就业市场的挑战。此外,该手册还鼓励学生通过网络平台和社会实践等多种途径积累人脉资源,增强自己的社交和交际技巧。 总的来说,CSU飞跃手册2019为学生提供了一个全面的指导工具,帮助他们更好地理解职业规划,提高个人素质,扩展职业视野并实现自我价值。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值