日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > POJ1270 Following Orders(拓撲排序)

POJ1270 Following Orders(拓撲排序)

來源:程序員人生   發布時間:2015-09-07 08:27:00 閱讀次數:4349次
Following Orders
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4059   Accepted: 1623

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 < y, you are to write a program that prints all orderings of the variables that are consistent with the constraints. 


For example, given the constraints x < y and x < z there are two orderings of the variables x, y, and z that are consistent with these constraints: x y z and x z y. 

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 < y. 


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

題意:給定1串字符(互異),再給出1個字符序列,表示1種前后關系,如a b e f c d,表示a<b,e<f,c<d。

將開始給出的字符進行排序,使之符合這個關系序列。并按字典序輸出這些符合要求的字符序列。

#include<stdio.h> #include<vector> #include<string.h> using namespace std; const int N = 30; int in[N],exist[N],mapt[N][N],path[N],n; void topeSort(int u,int k) { path[k]=u; if(k==n) { for(int i=1;i<=n;i++) printf("%c",path[i]+'a'); printf(" "); return ; } in[u]=⑴; for(int i=0;i<26;i++) if(mapt[u][i]) in[i]-=mapt[u][i]; for(int i=0;i<26;i++) if(exist[i]&&!in[i]) topeSort(i,k+1); in[u]=0; for(int i=0;i<26;i++) if(mapt[u][i]) in[i]+=mapt[u][i]; } int main() { int flag=0; char str[1000]; while(gets(str)) { if(flag)printf(" "); flag=1; memset(in,0,sizeof(in)); memset(exist,0,sizeof(exist)); memset(mapt,0,sizeof(mapt)); n=0; for(int i=0;str[i]!=' 主站蜘蛛池模板: 亚洲视频欧美视频 | 久久不射网 | 激情自拍偷拍 | 日韩欧美视频一区二区 | 自拍偷拍一区二区三区 | 久久久久久久久久国产精品 | 日本久久精品视频 | 91精品一区二区三区久久久久久 | 日韩视频网站在线观看 | 毛片一区 | 久久国产视频播放 | 国产成人av在线 | 久久久久亚洲精品国产 | 欧美日韩中文字幕 | 精品日产卡一卡二卡麻豆 | 国产高清在线精品一区二区三区 | 久草综合在线 | 在线观看黄色一级片 | 求av网站 | 一级色网站 | 国产激情在线观看 | 国产精品视频观看 | 国产精品18久久久久久久久 | 国产精品一区二区三区久久 | 国产精品电影网 | 日韩在线亚洲 | 日韩精品不卡 | 久久久一区二区 | 一级片在线播放 | 亚洲国产一区二区视频 | 精品视频一区二区 | 国产成人99久久亚洲综合精品 | 日韩视频在线一区 | 国产一二三区在线观看 | 欧美在线一区二区 | 亚洲精品乱码久久久久久按摩观 | 国产一区在线视频 | 亚洲国产高清在线 | www日韩在线 | 国产99久久精品一区二区永久免费 | 久久久久成人网 |