|
- #include<iostream>
- #include<cstdio>
- using namespace std;
- string ss;
- string s[101];
- int n;
- int f[105];
- bool judge(int l,string s)
- {
- if(ss.size()-l<s.size()) return false;
- for(int i=l;i<l+s.size();i++)
- if(ss[i]!=s[i-l]) return false;
- return true;
- }
- int dfs(int p)
- {
- if(f[p]) return f[p];
- if(p>=ss.size()) return 0;
- int ans=999999;
- for(int i=1;i<=n;i++)
- if(judge(p,s[i])) ans=min(dfs(p+s[i].size())+1,ans);
- return f[p]=ans;
- }
- int main()
- {
- freopen("word.in","r",stdin);
- freopen("word.out","w",stdout);
- cin>>ss;
- cin>>n;
- for(int i=1;i<=n;i++) cin>>s[i];
- dfs(0);
- cout<<f[0];
- return 0;
- }
复制代码 |
|