34
Name:
Anonymous
2011-05-25 11:04
#include <stdio.h>
#include <string.h>
#define BOWLS 40
#define ORANGES 9
int solutions = 0;
typedef char t_bowls[BOWLS];
typedef char t_dists[ORANGES][BOWLS];
void rec(int oranges, int pos, t_bowls i_bowls, t_dists i_dists)
{
int i, j, arec = pos+1 < BOWLS && oranges <= BOWLS-pos;
t_bowls bowls;
t_dists distances;
memcpy(bowls, i_bowls, sizeof(bowls));
memcpy(distances, i_dists, sizeof(distances));
if (arec) rec(oranges, pos+1, bowls, distances);
bowls[pos] = 1;
oranges--;
for(i = pos-1, j = oranges; i >= 0; i--) {
if (bowls[i]) {
int dist = pos - i; j++;
if (distances[j][dist]) return;
distances[oranges][dist] = 1;
}
}
if (!oranges) {
solutions++;
return;
}
if (arec) rec(oranges, pos+1, bowls, distances);
}
int main()
{
static t_dists distances;
rec(ORANGES, 0, (void*)distances, distances);
printf("%d\n", solutions);
return 0;
}
This is pointless, this damn thing just won't go much faster. Still waiting for that combinatorial solution, but I guess the mathematicians are satisfied just proving one exists.