这题爆搜不行吗 TLE6个点
查看原帖
这题爆搜不行吗 TLE6个点
600333
2672434062xzl楼主2024/3/9 11:49
#include<iostream>
#include<string>
using namespace std;
string s1,s2;
bool check(int pos1,int pos2){
	while(pos1<s1.length()&&pos2<s2.length()&&(s1[pos1]==s2[pos2]||s1[pos1]=='?')){
		++pos1;
		++pos2;
	}
	if(pos2==s2.length()){
		for(int i=pos1;i<s1.length();++i)if(s1[i]!='*')return 0;
		return 1;
	}
	if(pos1==s1.length())return 0;
	if(s1[pos1]=='*'){
		for(int i=0;pos2+i<=s2.length();++i)
			if(check(pos1+1,pos2+i))return 1;
	}
	return 0;
}
signed main() {
	cin>>s1;
	int t;
	for(cin>>t;t;--t){
		cin>>s2;
		if(check(0,0))puts("YES");
		else puts("NO");
	}
	return 0;
}

40分

2024/3/9 11:49
加载中...