各位大佬帮我看看代码
查看原帖
各位大佬帮我看看代码
1365344
huangruize楼主2024/7/11 16:49
#include<bits/stdc++.h>
using namespace std;
int n,res,vis[200];
string be,a[25];
bool check(string s1,string s2,int l){
	for(int i=0;i<l;i++){
		if(s1[s1.size()-l+i+1]!=s2[i-1])return false;
	}
	return true;
}
string add(string s1,string s2,int l){
	string t=s1;
	for(int i=l;i<=s2.size()-1;i++){
		t+=s2[i];
	}
	return t;
}
void bfs(string s){
	int l=s.size();
	res=max(res,l);
	for(int i=1;i<=n;i++){
		if(vis[i]>=2)continue;
		
		for(int j=1;j<=l;j++){
			if(check(s,a[i],j)){
				
				
				
				string t=add(s,a[i],j);
				if(s==t)continue;
				vis[i]++;
				bfs(t);
				vis[i]--;
			}
		}
		
	}
	return ;
}
int main (){
	cin>>n;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
	}
	cin>>be;
	bfs(be);
	cout<<res;
    return 0;
}
我到底哪里错了???
_______________________________________
2024/7/11 16:49
加载中...