gerbil kissing singer -> gerbilkissinger
kissing singer gerbil -> kissingerbil
maximal-ouroboros-compression(strings) best, key = compress_string(strings) foreach p = generate-permutations(strings) s, k = compress-string(p) if s.len() < best.len() best = s key = k return best, key
std::next-permutation()
generic algorithm.
{ kissing, singer } -> singer) singer -> { singer } { singer } -> { kissing singer, singer kissing }
{ kissing, singer, gerbil } -> { kissing, singer } { kissing, singer } -> { kissing singer, singer kissing } { kissing singer, singer kissing } -> { gerbil kissing singer, kissing gerbil singer, kissing singer gerbil, gerbil singer kissing, singer gerbil kissing, singer kissing gerbil }
permutations(strings) if strings.size == 1 return strings s = pick strings perms = { } for each p in permutations(strings) for each gap between words in p stick s in the gap and add the result to perms return perms
c | n | - | + | y | |
1 | 0 | 0 | 0 | 0 | 5 |
2 | 0 | 1 | 0 | 0 | 4 |
3 | 0 | 1 | 0 | 0 | 4 |
4 | 0 | 3 | 0 | 0 | 2 |
5 | 0 | 3 | 0 | 0 | 2 |
6 | 0 | 2 | 0 | 0 | 3 |
c | n | - | + | y | |
1 | 0 | 0 | 0 | 0 | 5 |
2 | 0 | 0 | 0 | 0 | 5 |
3 | 0 | 0 | 0 | 0 | 5 |
4 | 0 | 2 | 0 | 0 | 3 |
5 | 0 | 2 | 0 | 0 | 3 |
6 | 0 | 1 | 0 | 0 | 4 |
while true getline(cin, s)if !s.empty() && notallblanks(s)strvec.push_back(s)if (cin.eof()) break;
while getline(cin, s) if !s.empty() && notallblanks(s) strvec.push_back(s) if (not cin.eof()) std::cerr << "! input error..."
void findfromcomp ( string & st1, string & st2, int &i1, int &i2, vector <pair <int, int> >&ckey1, vector <pair <int, int> >&ckey2, int &comp_i, int &comp_j, vector <pair <string, int> >&ipvec, vector <pair <string, int> >&newipvec, vector <vector <pair <int, int> > >&key, vector <vector <pair <int, int> > >&newkey, vector <indi> &compressed, int i, int j) { void rrcompress( int idi,int idj,int idc,string &st1,int &i1, vector <pair <int, int> >&ckey1, string &st2, int &i2, vector <pair <int, int> >&ckey2, vector <pair <string, int> >&newipvec, vector <vector <pair <int, int> > >&newkey, vector <indi> &compressed, vector <pair <string,int> >&ipvec, vector <vector <pair <int, int> > >&key, vector <pair <string,int> >&fipvec, vector <vector <pair <int, int> > >&fkey, vector <int> &refvec,vector<int> &stadded, vector <indi> &indices) {
typedef
s typedef
s to define type synonyms.
typedef std::pair<int, int> int_pair; typedef std::vector<ipair> ipair_vec; typedef std::pair<std::string, int> strint_pair; typedef std::vector<strint_pair> strint_pairs;
typedef std::pair<int, int> key; typedef std::vector<key> keys; typedef std::pair<std::string, int> string_offset; typedef std::vector<string_offset> string_offsets;
// ou1**+ou2** // ou2** + ou1** // ou2 + ou1** // ou1 + ou2** // ou1** + ou2 // ou2** +ou1
/*single+mixed*/ // ou2 + ou1** if (ou1.getKey().size() > 1) && (comm < 0) && (ou2.getKey().size() == 1) comm* = -1 int fl = ou1.getFirstLength() int ll = ou1.getLastLength() list<uncom_key> k = ou1.getKeyWithoutFirst() return combineMixedCase1( str2, str1, key2, k, sz2, sz1, comm, fl, ll) // ou1 + ou2** else if (ou2.getKey().size() > 1) && (comm >= 0) && (ou1.getKey().size() == 1) int fl = ou2.getFirstLength() int ll = ou2.getLastLength() list<uncom_key> k = ou2.getKeyWithoutFirst() return combineMixedCase1( str1, str2, key1, k, sz1, sz2, comm, fl, ll)
static bool p(ou1, ou2) return (ou1.getKey().size() > 1) && (ou2.getKey().size() == 1) static int f(ou, str1, str2, key, sz1, sz2, comm) int f = ou.getFirstLength() int l = ou.getLastLength() list<uncom_key> k = ou.getKeyWithoutFirst() return combineMixedCase1( str1, str2, key, k, sz1, sz2, comm, f, l) if b(ou1, ou2) && (comm < 0) comm *= -1 return f(ou1, str2, str1, key2, sz2, sz1, comm) if b(ou2, ou1) && (comm >= 0) return f(ou2, str1, str2, key1, sz1, sz2, comm)
This page last modified on 18 March 2004.