标签:
realityour
5
real
reality
it
your
our
2
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<vector> using namespace std; const int sed = 31,Sed = 131,mod = 70177,Mod = 92311; int n,m,dp[205]; string a[205],s; vector<int> h[mod]; int main(){ cin>>s>>n; for(int i = 1;i <= n;i++){ cin>>a[i]; int hash = 0,Hash = 0; for(int j = 0;j < a[i].size();j++){ hash = (hash * sed + a[i][j]) % mod; Hash = (Hash * Sed + a[i][j]) % Mod; } h[hash].push_back(Hash); } m = s.size(); for(int i = 1;i <= m;i++) dp[i] = 999; for(int i = 1;i <= m;i++){ for(int j = i;j >= 1;j--){ int hash = 0,Hash = 0; for(int k = j - 1;k <= i - 1;k++){ hash = (hash * sed + s[k]) % mod; Hash = (Hash * Sed + s[k]) % Mod; } bool ok = false; for(int k = 0;k < h[hash].size();k++){ if(h[hash][k] == Hash){ ok = true; break; } } if(ok) dp[i] = min(dp[i],dp[j-1] + 1); } } cout<<dp[m]; return 0; }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/5791414.html