Tree Inside a Tree
Time limit1sMemory limit1024 MB
Count the ways to delete vertices and edges from perfect binary tree T_N so the remainder is isomorphic to perfect binary tree T_K, modulo 1000000007.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Tree, Combinatorics
- Solved
- No attempts yet
Problem
A perfect binary tree of height , , is an undirected graph with vertices numbered 1 to . For every integer with , there is an edge between vertex and vertex , and an edge between vertex and vertex .
Two graphs and are isomorphic if there is a one-to-one function such that for any two vertices and of , and are adjacent in if and only if and are adjacent in . Here and are the vertex sets of and .
Count the number of ways to remove zero or more vertices and edges from so that the resulting graph is isomorphic to .
Input
The first line contains two integers and , separated by a space. ()
Output
On the first line, print the answer modulo . is a prime number.