社区讨论

这题爆搜不行吗 TLE6个点

P3167[CQOI2014] 通配符匹配参与者 3已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@ltjjth8l
此快照首次捕获于
2024/03/09 11:51
2 年前
此快照最后确认于
2024/03/09 14:30
2 年前
查看原帖
CPP
#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分

回复

2 条回复,欢迎继续交流。

正在加载回复...