poj1270Following Orders(拓扑排序+dfs回溯)
2020-12-13 06:13
阅读:440
Following Orders
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 3800 | Accepted: 1502 |
Description
Order is an important concept in mathematics and in computer science. For example, Zorn‘s Lemma states: ``a partially ordered set in which every chain has an upper bound contains a maximal element.‘‘ Order is also important in reasoning about the fix-point
semantics of programs.
This problem involves neither Zorn‘s Lemma nor fix-point semantics, but does involve order.
Given a list of variable constraints of the form x
For example, given the constraints x
Input
The input consists of a sequence of constraint specifications. A specification consists of two lines: a list of variables on one line followed by a list of contraints on the next line. A constraint is given by a pair of variables, where x y indicates that x
All variables are single character, lower-case letters. There will be at least two variables, and no more than 20 variables in a specification. There will be at least one constraint, and no more than 50 constraints in a specification. There will be at least one, and no more than 300 orderings consistent with the contraints in a specification.
All variables are single character, lower-case letters. There will be at least two variables, and no more than 20 variables in a specification. There will be at least one constraint, and no more than 50 constraints in a specification. There will be at least one, and no more than 300 orderings consistent with the contraints in a specification.
Input is terminated by end-of-file.
Output
For each constraint specification, all orderings consistent with the constraints should be printed. Orderings are printed in lexicographical (alphabetical) order, one per line.
Output for different constraint specifications is separated by a blank line.
Sample Input
a b f g a b b f v w x y z v y x v z v w v
Sample Output
abfg abgf agbf gabf wxzvy wzxvy xwzvy xzwvy zwxvy zxwvy
Source
Duke Internet Programming Contest 1993,uva 124
下一篇:java8 新特性
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:poj1270Following Orders(拓扑排序+dfs回溯)
文章链接:http://soscw.com/essay/32737.html
文章标题:poj1270Following Orders(拓扑排序+dfs回溯)
文章链接:http://soscw.com/essay/32737.html
评论
亲,登录后才可以留言!