This topic is the length of the standard Complete Search, 350, even if the past cost is also small. Don't consider any optimization at all. Analysis method and me are almost, but written very elegant, very elegantly handled forward the forward direction (with an additional MOD function), and all white necklace problems. I didn't think that the entire necklace was white, and my method would fall into an Infinite loop. Consider the problem is not comprehensive
#include #include #include using namespace std; int findforward (vector , int, int); int FindBackward (Vector , int, int); int main () { INT N, // Number of Beads Maxlength; // Biggest Number of Beads Can Be Accumulated Vector Necklace; // Get Total Bead Number IFStream Fin ("Beads.in"); FIN >> N; // Get Every Bead for (int i = 0; i > bead; necklace.push_back (bead);} maxlength = 2; for (int i = 0; i n) {MAXLENGTH = n; break;}} ofstream fout ("beads.out"); fout << maxlength << endl;} int findforward (vector necklace, int pos, int size) {char currbead = necklace [POS]; char Beadtype = currbead; intleth = 1; int i = (POS 1)% size; if (currbead == 'w') {// count from White Bead, Jump To First Non -White One While (Necklace [I] == 'W') {Length ; i = (i 1)% size; if (length == size) return length;} beadtype = necklace [i];} while Necklace [i] == currbead || (necklace [i] == 'w') || (necklace [i] == beadType)) {Length ; i = (i 1)% size; if (length = = size) Break;} Return Length;} int FindBackward (Vector necklace, int pos, int size) {char currbead, // start point's color beadtype;