Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么我的一直WA,这不就是拓扑排序吗???#include<iostream> using namespace std; int indegree[20]={0};//入度数组 char vex[20];//节点数组 bool v[20]={0};//标记数组,标记节点是否已访问 int len;//节点个数 char stack[20];//存放结果的栈 int top=-1; bool bian[20][20]={0};//存放边 void Iopo_Sort(int &sum)//拓扑排序(递归) { int i,j; if(sum==300)return; if(top==len-1) { for(i=0;i<len;i++)cout<<stack[i]; cout<<endl; sum++; return; } for(i=0;i<len;i++) { if(indegree[i]==0&&!v[i]) { stack[++top]=vex[i]; v[i]=1; for(j=0;j<len;j++) if(bian[i][j])indegree[j]--; Iopo_Sort(sum); //===恢复记录============== for(j=0;j<len;j++) if(bian[i][j])indegree[j]++; v[i]=0; top--; } } } int main() { int i=0,j=0,k=0,sum=0; char c[210],d[110]; while(gets(c)) { //=============处理节点=========== i=0; j=0; while(c[i]!='\0') { if(c[i]!=' ')vex[j++]=c[i++]; else i++; } len=j; //======================== //===========处理边和入度============= gets(c); k=0; i=0; while(c[k]!='\0') { if(c[k]==' ')k++; else d[i++]=c[k++]; } char e,f,t1; for(j=0;j<i;j++) { e=d[j++]; f=d[j]; for(t1=0;t1<len;t1++)if(vex[t1]==e)break; for(k=0;k<len;k++)if(vex[k]==d[j]){indegree[k]++;break;} bian[t1][k]=1; } //======================================= sum=0; Iopo_Sort(sum); //================清理记录========================= for(i=0;i<20;i++)memset(bian,0,sizeof(bian)); memset(v,0,20); memset(indegree,0,sizeof(indegree)); top=-1; //=========================================== } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator