#define TEAM 0 /* Your team # here */ #define PROBLEM NUMBER /* The problem # here */ #include #include #include FILE *in=0; FILE *out=0; void solve_problem(); /*--------------------------------------------------------*/ int main(int argc, char *argv[]) { char inputFilename[64]; char outputFilename[64]; int teamNumber = TEAM; int j; sprintf(inputFilename, "prob%d.dat", PROBLEM); sprintf(outputFilename,"prob%d.out", PROBLEM); /* Process the command line arguments. This can change the filenames and/or team number */ j=1; while (j permutation[j]) sum++; } } counts[sum]++; } /*--------------------------------------------------------*/ void buildPermutations( int level ) { int j; if (level == size) testPermutation(); else { for (j=0; j 1) { answer *= (double) n; n--; } return answer; } /*--------------------------------------------------------*/ void solve_problem() { int j, k; double answers[21][200] = {0.0}; double total; double remainder; int array_size; int half; int numberInverted; /* initial case */ size = 0; answers[0][0] = 0.0; size = 1; answers[1][0] = 1.0; size = 2; answers[2][0] = 1.0; answers[2][1] = 1.0; size = 3; answers[3][0] = 1.0; answers[3][1] = 2.0; answers[3][2] = 2.0; answers[3][3] = 1.0; array_size = 7; for (size = 4; size<=20; size++) { half = array_size / 2; /* calculate the first "easy" half of the array */ total = 1.0; answers[size][0] = 1.0; for (j=1; j= size) { if (array_size % 2 == 1) answers[size][half] = remainder; else answers[size][half] = remainder/2.0; } /* copy the first half of the array to the second half but reverse it */ for (j=0, k=array_size-1; j <= half; j++, k--) answers[size][k] = answers[size][j]; if (size <= 10) /* compare these answers to the brute force answers for small permutations */ { for (j=0; j