Cod sursa(job #191149)

Utilizator stefysStefan stefys Data 25 mai 2008 14:28:06
Problema Cutii Scor 100
Compilator c Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
	unsigned int nrCutii, nrTeste, i, nrTest, x, y, z, max;
	unsigned int *cutieY, *cutieZ, *cutieMax;
	int j;
	freopen("cutii.in", "r", stdin);
	freopen("cutii.out", "w+", stdout);
	
	scanf("%u %u\n", &nrCutii, &nrTeste);
	cutieY   = malloc(sizeof(unsigned int)*nrCutii);
	cutieZ   = malloc(sizeof(unsigned int)*nrCutii);
	cutieMax = malloc(sizeof(unsigned int)*nrCutii);
	for (nrTest=0; nrTest<nrTeste; ++nrTest) {
		cutieMax[0] = 1;
		for (i=0; i<nrCutii; ++i) {
			scanf("%u %u %u\n", &x, &y, &z);
			--x;
			cutieY[x] = y-1;
			cutieZ[x] = z-1;
		}
		max = 1;
		for (i=1; i<nrCutii; ++i) {
			cutieMax[i] = 1;
			//cutieMax[i] = max{cutieMax[j] | j=i-1,1 && y[j]<y[x] && z[j]<z[x]
			for (j=i-1; j>=0; --j) {
				if (cutieY[j]<cutieY[i] && cutieZ[j]<cutieZ[i] && cutieMax[j]+1>cutieMax[i])
					cutieMax[i] = cutieMax[j]+1;
			}
			if (cutieMax[i] > max) max = cutieMax[i];
		}
		printf("%u\n", max);
	}
	
	free(cutieY); free(cutieZ); free(cutieMax);
	fclose(stdin);
	fclose(stdout);
	return 0;
}