I'm not doing it with DP yet. I'm almost positive my method works, and want to see it fail, before resorting to taking the DP approach.
I've tried mixing the strings so that the largest subsequences can be mixed in a random order, and i've tried tripling that approach, and I've tried adding random throw off characters, but I can't break my program. However it gets WA.
Here are 2 inputs I've used, first being the shortest complex string I could think of, and the second being the same with a lot of random characters in between:
Code: Select all
abcdxzyacdxzyb
acdxzybabcdxzy
a436432b5c346d23x6z56y54a62c6dx64665426z2y6b26
uaiopciudopxipzioypoibpuaobpcioodpiuxpozpy
Here's my code:
Code: Select all
#include <iostream>
#include <string>
#include <vector>
using namespace std; //status: completed, again they giving fucking terrible input, so obviously I can't get it accepted.
string s1, s2; //flip it around and compare it again? Tyr this and evaluate!
int maxsub; //also wiki longest common subsequence.
int s2iter; int s1iter;
void countinstuff()
{
int max=1000000000, dist=0,temp,s2loc; bool foundone;
/*find next occurance of a letter*/
int i;
for(i=0; i<s1.length(); i++)
if(s2iter=s2.find(s1[i])+1) //this means it doesn't find anything... better then ==string::npos
break;
//cout << "Found first match at " << i<<", "<<(s2iter-1)<<endl;
/***/
for(int k=i; k<s1.length(); k++)
{
int bleh=k;
foundone=false;
max=1000000000;
//cout << "k now equals " << k << endl;
for(int j=k; j<s1.length(); j++)
{
/*find next occurance of a letter*/
for(i=j; i<s1.length(); i++)
if(temp=s2.find(s1[i],s2iter)+1) //this means it doesn't find anything... better then ==string::npos
break;
//cout << "Found a match at " << i<<", "<<(temp-1)<<endl;
j=i;
if(j==s1.length() && !foundone) k=s1.length();
else foundone=true;
/***/
//cerr << "max = " << max << " & last dist = " << dist << endl;
if(j!=s1.length())
{ if((dist=(j-bleh)+(temp-s2iter))<max)
{
//cerr << "found better match at " <<j<<", "<<temp-1<<"while respectivly, k and s2iter are: "<<k<<", "<<s2iter<<endl;
max=dist;
s2loc=temp;
k=j;
}}
}
s2iter=s2loc;
//cout << "Found best match at " << k<<", "<<(s2iter-1)<<endl;
if(foundone) maxsub++;
//cout << "maxsub now equals " << maxsub << endl;
}
//cout << "**************************"<<endl;
}
int main()
{
while(cin >> s1)
{
cin >> s2;
s2iter=0;
maxsub=1;
//cout << "s1=" << s1 << " s2=" << s2<<endl;
countinstuff();
//cout << "maxsub=" << maxsub << " (before swap)"<<endl;
cout << maxsub << endl;
}
return 0;
}
All i need is a complex input to break my code. Preferably not too long, so it isn't too hard to trace ^^.