Cod sursa(job #66268)

Utilizator scapryConstantin Berzan scapry Data 17 iunie 2007 12:03:54
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <stdio.h>
#include <assert.h>

enum { maxboxes = 3502 };

int boxes;
int dim[maxboxes][2]; //dimensions y and z (sorted by x)
int best[maxboxes]; //best using box i and beneath
int ans;

void go()
{
	int i, j;

	best[0] = 0; //I don't exist
	best[1] = 1; //me
	ans = 1;

	for(i = 2; i <= boxes; i++)
	{
		best[i] = 1; //me

		for(j = 0; j < i; j++)
		{
			if(dim[j][0] < dim[i][0] && dim[j][1] < dim[i][1])
				if(best[j] + 1 > best[i])
					best[i] = best[j] + 1;
		}

		printf("best[%d] %d\n", i, best[i]);

		if(best[i] > ans)
			ans = best[i];
	}

	printf("------------------ ans %d\n\n", ans);
}

int main()
{
	int i, j, x, y, z, tests;
	FILE *fi = fopen("cutii.in", "r"),
	     *fo = fopen("cutii.out", "w");
	if(!fi || !fo) return 1;

	fscanf(fi, "%d%d", &boxes, &tests);
	for(i = 0; i < tests; i++)
	{
		for(j = 0; j < boxes; j++)
		{
			fscanf(fi, "%d%d%d", &x, &y, &z);
			dim[x][0] = y;
			dim[x][1] = z;
		}

		go();

		fprintf(fo, "%d\n", ans);
	}

	fclose(fi);
	fclose(fo);
	return 0;
}