CCC 2011 J5 Unfriend 题解

该博客详细介绍了 CCC 2011 J5 题目,涉及社交网络中的人脉关系。问题要求计算在删除一个人及其邀请的联系人时,有多少种不同的删除组合。输入输出格式和样例数据也进行了说明。博主通过深度优先搜索(DFS)和动态规划(DP)方法进行了题解,并提供了DP状态转移方程。
摘要由CSDN通过智能技术生成

题面

题目传送门(题目在第10页)
Problem Description
Mark invited some people to join his social network. Some of them invited new people, who
invited new people, and so on. Now there are N N N people in the network, numbered from 1 1 1 to N N N .
Mark has decided to remove some people and keep others. There is one restriction: when removing
a person, he will also remove the people s/he invited, and the people they invited, and so on. Mark
will never remove himself, and we do not allow people to be invited by more than one person.
Mark can also decide to not remove anyone.
How many different sets of people can be removed?
Input Specification:
The first line contains a single integer N N N ( N ≤ 6 N ≤ 6 N6 ), the number of people in the network. Next are
N − 1 N − 1 N1 lines telling us who invited each person. To be precise, line i in this set ( 1 ≤ i ≤ N − 1 1 ≤ i ≤ N − 1 1iN1 )
contains a single integer j j j (with j > i j > i j>i ), which indicates that person j j j is the person who invited
person i i i. Person N N N is Mark.
Output Specification:
Output a single integer, the number of possible sets of people that can be removed.
Sample Input 1

3
3
3

Output for Sample Input 1
4
Explanation for Sample 1
The first number of the input indicates there are three people in the network. The next line tells
us that Person 1 was invited by Mark, while the last line tells us that Person 2 was also invited by
Mark. The sets of people that can be removed are { } \{\} { }, { 1 } \{1\} { 1}, { 2 } \{2\} { 2}, { 1 , 2 } \{1,2\} { 1,2} .
Sample Input 2
4 3 4 4
Output for Sample Input 2
6 10
Explanation for Sample 2
There are 4 4 4 people in the network. Here is a table of who invited who:

Person inviting Invited
1 1 1 none
2 2 2 none
3 3 3 1 1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值