Cod sursa(job #514551)

Utilizator ShootMeBistriceanu Andrei ShootMe Data 19 decembrie 2010 01:00:55
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <stdio.h>
#include <algorithm>

using namespace std;

struct threed_point {
  int x, y, z;
};

int n, t;
struct threed_point a[3501];


int compare (const void * a, const void * b)
{
  struct threed_point *p1 = (threed_point *) a;
  struct threed_point *p2 = (threed_point *) b;

/*  int z_cond = p1->z - p2->z;
  int y_cond = (p1->y != p2->y) ? p1->y - p2->y : z_cond;

  return (p1->x != p2->x) ? p1->x - p2->x : (y_cond);
*/
  return p1->x - p2->x;
}

void solve() {
  qsort(a, n, sizeof(threed_point), compare);
/*  for (int i = 0; i < n; i++) {
    printf("%d %d %d\n", a[i].x, a[i].y, a[i].z);
  }
  printf("\n\n\n");
*/
  int opt[3501];
  for (int i = 0; i < n; i++) opt[i] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = i - 1; j >= 0; j --) {
      if (a[j].x < a[i].x && a[j].y < a[i].y && a[j].z < a[i].z && opt[j] + 1 > opt[i]) {
         opt[i] = opt[j] + 1;
      }
    }
  }
  int max = 0;
  for (int i = 0; i < n; i++) {
    if (opt[i] > max) max = opt[i];
  }
  printf("%d\n", max);
}

int main() {
  freopen("cutii.in", "r", stdin);
  freopen("cutii.out", "w", stdout);

  scanf("%d %d", &n, &t);

  for (int i = 0; i < t; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d %d %d", &a[j].x, &a[j].y, &a[j].z);
    }
    solve();
  }


  return 0;
}