Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

2D dynamic bool array?

Name: Anonymous 2006-01-03 16:44

I want to create a 2D dynamic bool array (or char is fine too). I'm doing the n-queens problem and I've figured everything out except for this part. Any help?

Name: Anonymous 2006-01-12 0:01

well, looking at it again, i got it.
int N = 5;
int cities[N] = {5,3,2,8,7};
int *ctsums;

int distance (int a, int b) { return (ctsums[b-1]-ctsums[a-1]); }

void make_ctsums () {
  ctsums = malloc(N);

  int i,acc=0;
  for (i=0; i++; i<N) {
    acc += cities[i];
    ctsums[i] = acc;
  }
}
O(n) space and init time. O(1) lookup. the solution was just staring at me...i can't believe i didn't see it before.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List