提交时间:2021-05-17 18:21:32

运行 ID: 19606

#include<bits/stdc++.h> using namespace std; int n; char Head[51]; char Tail[51]; int Flag[51]={1}; int Answer,Count=1; int Solitaire(int x){ for(int i=2;i<=n;i++){ if(Head[i]==Tail[x]&&Flag[i]!=1&&i!=x){ Flag[i]=1; Count++; Solitaire(i); Flag[i]=0; } } if(Count>Answer){ Answer=Count; Count--; return 0; } } int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>Head[i]; cin>>Tail[i]; } Solitaire(1); cout<<Answer; return 0; }