Following Orders Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4885 Accepted: 1973 Description Order is an important concept in mathematics and in computer science. For example, Zorn's Lemma states: ``a partially ordered set in which…
http://poj.org/problem?id=1270 题目大意: 给你一串序列,然后再给你他们部分的大小,要求你输出他们从小到大的所有排列. 如a b f g 然后 a<b ,b< f 那么符合要求的有abfg abgf agbf gabf(即不能出现(a在b后面,b在f后面) 思路: 把这些字符看成点,如果存在a<b的关系,则在有向图中建立一条边 v(a,b),然后进行拓扑排序. 话说这题的输入很坑爹,那个大小关系的我还以为是4个一组..结果被坑死了.看了discu…
Following Orders Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4254 Accepted: 1709 Description Order is an important concept in mathematics and in computer science. For example, Zorn's Lemma states: ``a partially ordered set in which…
题意: 给两行字符串,第一行为一组变量,第二行时一组约束(每个约束包含两个变量,x y 表示 x <y).输出满足约束的所有字符串序列. 思路:拓扑排序 + 深度优先搜索(DFS算法) 课本代码: #include<iostream> #include<cstring> #include<string> using namespace std; int n; int pre[300]; // 存字母入度// 把小写字母的ascii码都包括在内 bool has[3…
题目链接:http://codeforces.com/contest/883/problem/B There are n military men in the Berland army. Some of them have given orders to other military men by now. Given m pairs (xi, yi), meaning that the military man xi gave the i-th order to another milita…