1. 程式人生 > >HDU 5379 Mahjong tree(樹的遍歷&組合數學)

HDU 5379 Mahjong tree(樹的遍歷&組合數學)

Little sun is an artist. Today he is playing mahjong alone. He suddenly feels that the tree in the yard doesn't look good. So he wants to decorate the tree.(The tree has n vertexs, indexed from 1 to n.) Thought for a long time, finally he decides to use the mahjong to decorate the tree. His mahjong is strange because all of the mahjong tiles had a distinct index.(Little sun has only n mahjong tiles, and the mahjong tiles indexed from 1 to n.) He put the mahjong tiles on the vertexs of the tree. As is known to all, little sun is an artist. So he want to decorate the tree as beautiful as possible. His decoration rules are as follows: (1)Place exact one mahjong tile on each vertex. (2)The mahjong tiles' index must be continues which are placed on the son vertexs of a vertex. (3)The mahjong tiles' index must be continues which are placed on the vertexs of any subtrees. Now he want to know that he can obtain how many different beautiful mahjong tree using these rules, because of the answer can be very large, you need output the answer modulo 1e9 + 7.