Hi i have this program i got off the net, im a beginner on this stuff so i try explain best i can :)
i think programs have a sort in place to check if array is in 1 to N order before permutation call, if i was to leave out the sort then i could put values where i want to speed things up.
e.g: say{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,30,29,28,27,26,25,24,23,22,21,20,19,18,17,
15,16}
and i had to stop the program...(restart pc or other reason)
next time i start the program i change the array to order it finished at so i dont have to go through array from the beginning?
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
|
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
//using arrays of string
void display(string* strstart, string* strend)
{
for(string* it= strstart;it!=strend;++it)
cout<<*it<<" ";
cout<<endl;
}
int main()
{
string* strarray=new string[31];
strarray[0]="ON";
strarray[1]="OFF";
strarray[2]="ON";
strarray[3]="OFF";
strarray[4]="ON";
strarray[5]="OFF";
strarray[6]="ON";
strarray[7]="OFF";
strarray[8]="ON";
strarray[9]="OFF";
strarray[10]="ON";
strarray[11]="OFF";
strarray[12]="ON";
strarray[13]="OFF";
strarray[14]="ON";
strarray[15]="OFF";
strarray[16]="ON";
strarray[17]="OFF";
strarray[18]="ON";
strarray[19]="OFF";
strarray[20]="ON";
strarray[21]="OFF";
strarray[22]="ON";
strarray[23]="OFF";
strarray[24]="ON";
strarray[25]="OFF";
strarray[26]="ON";
strarray[27]="OFF";
strarray[28]="ON";
strarray[29]="OFF";
strarray[30]="ON";
display(strarray,strarray+31);
for(int i=0; i<8.22283865417792281772556288e+33 -1; ++i)
{
next_permutation(strarray,strarray+31);
display(strarray,strarray+31);
}
return 0;
}
|
Thanks :)