Cod sursa(job #514552)

Utilizator ShootMeBistriceanu Andrei ShootMe Data 19 decembrie 2010 01:05:36
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 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;

  return p1->x - p2->x;
}

void solve() {
  qsort(a, n, sizeof(threed_point), compare);

  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;
}