Arpa and choosing brother free subset
Practice
3.1 (26 votes)
Algorithms
Dynamic programming
Medium
Problem
90% Success 3688 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code
Arpas family consists of $$n$$ men. We can show them with a rooted tree with $$n$$ vertices. Arpa wants to choose $$k$$ of them for playing football but he shouldn't choose someone and his brother too. In short, there should be no direct siblings, both selected for playing football. Print in how many ways he can choose this set modulo $$10^9+7$$.
Input Format
The first line contains two integers, n, k (\(1 \leq n \leq 10^5, 0 \leq k \leq 100\)).
The second line contains $$n-1$$ integers \(p_2, p_3, \ldots, p_n\) (\(p_i < i\)) -- $$p_i$$ is the index of the parent of $$i$$-th person.
Output Format
Print in how many ways he can choose this set modulo $$10^9+7$$.
Submissions
Please login to view your submissions
Similar Problems
Points:30
6 votes
Tags:
1-DAlgorithmsDynamic ProgrammingBitmaskDynamic Programming and Bit Masking
Points:30
31 votes
Tags:
AlgorithmsApprovedBit ManipulationDynamic ProgrammingMediumOpen
Points:30
47 votes
Tags:
AlgorithmsApprovedBit ManipulationDynamic ProgrammingMediumReady
Editorial