-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathGenome-Sequencing.cpp
76 lines (64 loc) · 1.89 KB
/
Genome-Sequencing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
int main()
{
int N;
cin >> N; cin.ignore();
vector<string> subseqs(N);
vector<int> order(N);
for (int i = 0; i < N; i++) {
string subseq;
cin >> subseq; cin.ignore();
subseqs[i] = subseq;
order[i] = i;
}
string bestWord;
string lastWord;
do
{
bool match = false;
string lastWord = subseqs[order[0]];
for (unsigned int i = 1; i < subseqs.size(); ++i)
{
match = false;
string first = lastWord;
string second = subseqs[order[i]];
for (unsigned int j = 0; j < first.size(); ++j)
{
if (second.size() >= first.size() - j)
{
match = equal(first.begin() + j,
first.end(),
second.begin());
if (match)
{
lastWord = first + second.substr(first.size() - j);
break;
}
}
else
{
match = equal(first.begin() + j,
first.begin() + j + second.size(),
second.begin());
if (match)
{
lastWord = first;
break;
}
}
}
// If no overlap, place the sequences begind each other
if (!match)
lastWord = first + second;
}
if (bestWord.empty() || (lastWord.size() < bestWord.size()))
bestWord = lastWord;
}
while (next_permutation(order.begin(), order.end()));
cout << bestWord.size() << endl;
}