Mahjong tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 388    Accepted Submission(s): 125 Problem Description Little sun is an artist. Today he is playing mahjong alone. He suddenly feels…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5379 题意:一颗n个节点n-1条边的树,现在要给每个节点标号(1~n),要求:(1)每一层的兄弟节点的标号要是连续的(2)每一颗子树的所有节点标号是连续的.问有多少种标号方案. 解法:对于每一层顶多只能存在2个非叶子节点,否则无解:对于每一层有x个叶子节点,y个非叶子节点,那么ans=(ans * x!)%mod,另外如果y!=0,还得ans=2*ans%mod. #include <bits/st…
题目链接: Hdu 5379 Mahjong tree 题目描述: 给出一个有n个节点的树,以节点1为根节点.问在满足兄弟节点连续 以及 子树包含节点连续 的条件下,有多少种编号方案给树上的n个点编号? 解题思路: 对于一个节点来讲,非叶子儿子节点最多有两个才能满足要求,否则满足子树节点连续的话就无法满足兄弟节点连续.然后有dfs计算每棵子树的贡献值,每棵子树的子节点可以分为叶子节点X和非叶子节点Y,叶子节点可以分配到一组连续的编号,非叶子节点只能分配到兄弟节点中最大或者最小编号两种情况,叶子节…
题目链接:pid=5379">http://acm.hdu.edu.cn/showproblem.php? pid=5379 Problem Description 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 tre…
本文纯属原创,转载请注明出处.谢谢. http://blog.csdn.net/zip_fan 题目传送门:http://acm.hdu.edu.cn/showproblem.php? pid=5379 Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Little sun is an artist. Today he is playing…
题意:在一棵有n个节点的树上放编号从1到n的麻将,要求每个点的儿子节点之间的编号连续,每棵子树内的编号连续. 解法:手推一组样例之后就可以得到如下结论然后从根节点一边讨论一边搜就好了. 当一个节点只有一个儿子的时候,如果儿子是叶子节点则只有一种放法,如果儿子不是叶子节点则有两种放法. 当一个节点有两个儿子的时候,一定有两种放法. 当一个儿子有三个儿子及以上的时候,假设有k个儿子,如果非叶子节点m的个数为0则有k!种放法,如果m为1,则有2 × (k - 1)!种放法,如果m为2,则有2 × (k…
Mahjong tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 768    Accepted Submission(s): 241 Problem Description Little sun is an artist. Today he is playing mahjong alone. He suddenly feels…
题意:给你一棵树来分配号码,要求是兄弟节点连续并且每一棵子树连续. 思路:因为要求兄弟和子树都是连续的,所以自己打下草稿就可以发现如果一个节点有3个或3个以上的非叶子结点,那么就无论如何也不能达到目的.  现在假设一个节点有x个非叶的子节点,y个叶子子节点. 若x = 0,对于这棵子树,父节点只能取两端的号码才能使兄弟节点连续,y个叶子节点则有一个全排列,因此当前的方案数有 y! * 2 若x = 1,且这颗非叶子节点构成的子树的方案数是f[a],方案数为 y! * f[a] * 2 若x =…
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 539064-bit integer IO format: %I64d      Java class name: Main   Given a rooted tree(node 1 is the root) with n nodes. The ithnode has a positive value vi…
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 538364-bit integer IO format: %I64d      Java class name: Main   "Yu-Gi-Oh!", also known as "Dueling Monsters", is a popular trading ca…