辖网站建设 网站设计,北京市建设工程交易网信息网,商鼎营销型网站建设,室内设计需要什么学历E. Pattern Matching
首先p[mtj]p[mt_j]p[mtj]必须能够匹配所给字符sjs_jsj#xff0c;然后把所有能够匹配的sjs_jsj的其他模板串也找出来#xff0c;这些必须放在p[mtj]p[mt_j]p[mtj]的后面#xff0c;典型拓扑排序#xff0c;连边然后排序即可
#define IO ios:…E. Pattern Matching
首先p[mtj]p[mt_j]p[mtj]必须能够匹配所给字符sjs_jsj然后把所有能够匹配的sjs_jsj的其他模板串也找出来这些必须放在p[mtj]p[mt_j]p[mtj]的后面典型拓扑排序连边然后排序即可
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#includeset
#includemap
#includecmath
#includestack
#includequeue
#includebitset
#includerandom
#includebitset
#includestring
#includevector
#includecstdio
#includecstring
#includeiostream
#includealgorithm
#includeunordered_map
#includeunordered_set
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pairll,int pli;
typedef pairint,int pii;
//
const int N200010;
int n,m,k;
mapstring,int mp;
vectorint E[N]; // 邻接表
int d[N];
int main()
{//IO;int T1;//cinT;while(T--){cinnmk;for(int i1;in;i){string s;cins;mp[s]i;}bool ok1;for(int i1;im;i){string s;int pos;cinspos;if(!ok) break;bool flag0;for(int j0;j1k;j){string t(s);for(int l0;lk;l)if(jl1)t[l]_;if(mp.count(t)) {if(mp[t]!pos)E[pos].push_back(mp[t]),d[mp[t]];elseflag1;// 该位置必须能够匹配}}if(!flag) ok0;}if(ok){queueint q;for(int i1;in;i)if(!d[i]) q.push(i);vectorint ans;while(q.size()){int tq.front();q.pop();ans.push_back(t);for(auto v:E[t])if(--d[v]0) q.push(v);}if(ans.size()n){coutYES\n;for(auto t:ans) coutt ;}elsecoutNO\n;}elsecoutNO\n;}return 0;
} 心路历程 刚开始理解成把原匹配串重排列然后一一对应 字符串匹配直接暴力枚举最多24162^4162416匹配然后二分匹配随便搞搞写完发现题意中有一个first匹配然后发现理解错了然后······重看一遍又写发现又看错了然后看了看网上题意解释真的语文水平。。。