Longest Prefix
给定一堆小字符串,问最长可以组成给定的大字符串的多少位前缀。
类似于DP的思想,标记出结束位置。看最远结束在哪里。
#include <bits/stdc++.h> using namespace std; const int N = 1205; const int M = 200004; string ch[N]; char st[100]; bool ok[M]; int main() { string str = ""; string s; freopen("prefix.in","r",stdin); #ifndef poi freopen("prefix.out","w",stdout); #endif int id = 1; int i, j, k; cin >> st ; while(st[0] != '.') { ch[id] = (string)st; // cout << ch[id] << endl; id++; cin >> st; } id --; while(cin>>s) str += s; int len = str.length(); ok[0] = true; int ans; for(i = 0; i <= len; i++){ if(!ok[i])continue; ans = i; for(j = 1; j <= id; j++){ for(k = 0; ch[j][k] != '