Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inline int const factorial(int x) {
- return x==1?1:x*factorial(x-1);
- }
- inline int const pow(int a, int b){
- return b==1?a:a*pow(a,b-1);
- }
- const int num = 7;
- int** ptable;
- void initptable() {
- ptable=(int**)malloc(sizeof(int*)*factorial(num));
- for(int i=0;i<factorial(num);i++){
- ptable[i]=(int*)malloc(sizeof(int)*num);
- for(int j=0;j<num;j++)(ptable[i])[j]=-1;
- }
- (ptable[0])[0]=0;
- for(int i=1;i<num;i++){
- for(int j=1;j<i+1;j++){
- for(int k=0;k<factorial(i);k++){
- for(int l=0;l<num;l++){
- (ptable[j*factorial(i)+k])[l]=(ptable[k])[l];
- }
- }
- }
- for(int j=0;j<i+1;j++){
- for(int k=0;k<factorial(i);k++){
- for(int l=i;l>j;l--){
- (ptable[j*factorial(i)+k])[l]=(ptable[j*factorial(i)+k])[l-1];
- }
- (ptable[j*factorial(i)+k])[j]=i;
- }
- }
- }
- for(int i=0;i<factorial(num);i++){
- for(int j=0;j<num;j++){
- (ptable[i])[j]=num-1-(ptable[i])[j];
- }
- }
- }
- inline int perm(int* x) {
- for(int i=0;i<factorial(num);i++){
- char flag=1;
- for(int j=0;j<num;j++){
- if(x[j]!=(ptable[i])[j])flag=0;
- }
- if(flag)return i;
- }
- return -1;
- }
- int main (int argc, char** argv) {
- initptable();
- char* nets=(char*)malloc(factorial(num));
- for(int i=0;i<factorial(num);i++)nets[i]=0;
- for(int i=0;i<factorial(num);i++){
- if(nets[i])continue;
- nets[i]|=1;
- int* c=(int*)malloc(sizeof(int)*num);
- for(int j=0;j<num;j++)c[j]=(ptable[i])[j];
- for(int h=0;h<num;h++){
- for(int j=0;j<num;j++){
- nets[perm(c)]|=2;
- for(int k=0;k<num;k++){
- c[k]=(c[k]+1)%num;
- }
- }
- for(int j=0;j<num/2;j++){
- int tmp=c[j];
- c[j]=c[num-1-j];
- c[num-1-j]=tmp;
- }
- for(int j=0;j<num;j++){
- nets[perm(c)]|=2;
- for(int k=0;k<num;k++){
- c[k]=(c[k]+1)%num;
- }
- }
- for(int j=0;j<num/2;j++){
- int tmp=c[j];
- c[j]=c[num-1-j];
- c[num-1-j]=tmp;
- }
- int tmp=c[0];
- for(int j=0;j<num-1;j++){
- c[j]=c[j+1];
- }
- c[num-1]=tmp;
- }
- }
- int s=0;
- for(int i=0;i<factorial(num);i++){
- if(nets[i]&1){
- s++;
- for(int j=0;j<num;j++){
- cout<<(char)((ptable[i])[j]+65);
- }
- cout<<endl;
- }
- }
- cout<<s<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement