UVA11174 Stand in a Line】的更多相关文章

题意 PDF 分析 \[ f(i)=f(c_1)f(c_2)\dots\times(s(i)-1)!/(s(c_1)!s(c_2)! \dots s(c_k)! )\\ f(root)=(s(root)-1)!/(s(1)s(2)s(3)\dots s(n)) \] 预处理阶乘以及逆元. 时间复杂度\(O(Tn)\) 代码 #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath>…
// uva 11174 Stand in a Line // // 题目大意: // // 村子有n个村民,有多少种方法,使村民排成一条线 // 使得没有人站在他父亲的前面. // // 解题思路: // // 换成模型,先将森林变成一棵树,这样就直观多了,对于 // 一个节点,他的子节点排列时没有任何要求,而子排列中会有 // 限制,将这些限制先提取出来,就可以将所有的视为相同的了, // 然后就是有重复元素的全排列问题.设s(i)为以i节点为根的子树 // f(i)为以i为根的子树的排法,…
Problem J Stand in a Line Input: Standard Input Output: Standard Output All the people in the byteland want to stand in a line in such a way that no person stands closer to the front of the line than his father. You are given the information about th…
http://blog.csdn.net/u011915301/article/details/43883039 依旧是<训练指南>上的一道例题.书上讲的比较抽象,下面就把解法具体一下.因为涉及到父子关系,因此自然而然可以将n个节点构造成一棵树,最后将形成一个森林.接下来将使用递归的手法.设f(i)是以节点i为树根的子树,节点i有儿子c1,c2,c3....cj共j棵子树.s[i]为树根为i的子树包含的节点数.如果分别先给各个子树内部排序,那么毫无疑问, 共有f(c1)*f(c2)*f(c3)…
题意:村子里有n个人,给出父亲和儿子的关系,有多少种方式可以把他们排成一列,使得没人会排在他父亲的前面 思路:设f[i]表示以i为根的子树有f[i]种排法,节点i的各个子树的根节点,即它的儿子为c1,c2,c3...ck. 那么先给节点i的子树确定各自的顺序,为f(c1),f(c2)...f(ck). 然后把每棵子树的所有节点看成同一元素,根据有重复元素的全排列方式共有s(i-1)!/(s(c1)!*s(c2)!*...*s(ck)!) 再根据乘法原理,f[i]=f(c1)* f(c2) *f(…
题意: 有n个人排队,要求每个人不能排在自己父亲的前面(如果有的话),求所有的排队方案数模1e9+7的值. 分析: <训练指南>上分析得挺清楚的,把公式贴一下吧: 设f(i)为以i为根节点的子树的排列方法,s(i)表示以i为根的子树的节点总数. f(i) = f(c1)f(c2)...f(ck)×(s(i)-1)!/(s(c1)!s(c2)!...s(ck)!) 按照书上最开始举的例子,其实这个式子也不难理解,就是先给这些子树确定一下位置,即有重元素的全排列. 子树的位置确定好以后,然后再确定…
主题链接:点击打开链接 题意:白书的P103. 加个虚根就能够了...然后就是一个多重集排列. import java.io.PrintWriter; import java.util.ArrayList; import java.util.Scanner; public class Main { static int N = 40100; ArrayList<Integer>[] G = new ArrayList[N]; static long mod = 1000000007; long…
UVA 11174 考虑每个人(t)的所有子女,在全排列中,t可以和他的任意子女交换位置构成新的排列,所以全排列n!/所有人的子女数连乘   即是答案 当然由于有MOD 要求逆. #include <cstdio> #include <cstring> #include <vector> using namespace std; typedef long long ll; const int N = 40005; const ll MOD = 1e9+7; int n,…
这两个题的模型是有n个人,有若干的关系表示谁是谁的父亲,让他们进行排队,且父亲必须排在儿子前面(不一定相邻).求排列数. 我们假设s[i]是i这个节点,他们一家子的总个数(或者换句话说,等于他的子孙数+1(1是他本身)),f[i]是以i为根的节点的排列种数.那么总的种数为n!/(s[1]+s[2]+...+s[n]).关于这个递推式的得出,是根据排列公式的,我们假设一个例子,不妨设4.5是2的子孙,3是1的子孙.那么他们进行排队的话,不妨看成222和11排队就是2的家族和1的家族排队(2和1是平…
UVa Online Judge 训练指南的题目. 题意是,给出n个人,以及一些关系,要求对这n个人构成一个排列,其中父亲必须排在儿子的前面.问一共有多少种方式. 做法是,对于每一个父节点,将它的儿子结点构成的子树看成无序状态,这样子对当前父节点整棵树计算一个排列数.如果把所有的这样的式子写出来,可以发现分子分母是可以相消的.假设点的总数是S,儿子的点的数目分别是A,B,C...,这样的话,对于这个结点,可以求得F(S)=F(A)+F(B)+F(C)+....最后的结果是所有子树的F(S)*F(…
G. Happy Line time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a larg…
[codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of n Berland residents lined up in front of the ice cream stall. We know that ea…
Happy Line Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 549G Description Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this…
非常有趣的贪婪: Let's reformulate the condition in terms of a certain height the towers, which will be on the stairs. Then an appropriate amount of money of a person in the queue is equal to the height of the tower with the height of the step at which the t…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3743 Frosh Week Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 5   Accepted Submission(s) : 1 Font: Times New Roman | Verdana | Georgia Font Size: …
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo…
原题链接 Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historian living in 1st century. He and his 40 comrade soldiers were trapped in a cave, the exit of which was blocked by Romans. They chose suicide over captu…
Problem Description There are N robots standing on the ground (Don't know why. Don't know how). Suddenly the sky turns into gray, and lightning storm comes! Unfortunately, one of the robots is stuck by the lightning!So it becomes overladen. Once a ro…
Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 30    Accepted Submission(s): 20 Problem Description Farmer John likes to play mathematics games with his N cows. Recently, the…
POJ  2761 Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed the dogs every day for Wind. Jiajia loves Wind, but not the dogs, so Jiajia use a special way to feed the dogs. At lunchtime, the dogs will stand on…
Gunner  Accepts: 391  Submissions: 1397  Time Limit: 8000/4000 MS (Java/Others)  Memory Limit: 65536/65536 K (Java/Others) Problem Description Long long ago, there is a gunner whose name is Jack. He likes to go hunting very much. One day he go to the…
Children’s Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13333    Accepted Submission(s): 4364 Problem Description There are many students in PHT School. One day, the headmaster whose na…
Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of t…
Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Farmer John likes to play mathematics games with his N cows. Recently, they are attracted by recursive sequences. In each turn,…
转载自:http://magicpanda.net/2010/10/lua%E6%9E%B6%E6%9E%84%E6%96%87%E6%A1%A3/ Lua架构文档(翻译) 十 102010 前段时间翻译了lua官方关于lua5架构设计的一份文档,现在分享给大家. 注意:所有版权都归lua官方所有,本人仅将其翻译为中文,以方便中文阅读者.翻译中出现任何错误导致的结果,本人不负任何责任. 如果有任何翻译错误,以及意见与建议,请email本人.邮件地址:ice_ok@163.com. 转载请注明原作…
原文链接:Multithreading and Grand Central Dispatch on iOS for Beginners Tutorial Have you ever written an app where you tried to do something,and there was a long pause while the UI was unresponsive?This is usually a sign that your app needs multithreadi…
B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/427/B Description The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c…
题目链接: http://acm.hust.edu.cn/vjudge/contest/122094#problem/H Frosh Week Time Limit:8000MSMemory Limit:0KB 问题描述 During Frosh Week, students play various fun games to get to know each other and compete against other teams. In one such game, all the fro…
H - Frosh Week Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description During Frosh Week, students play various fun games to get to know each other and compete against other team…
Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 249    Accepted Submission(s): 140 Problem Description Farmer John likes to play mathematics games with his N cows. Recently, t…