Pagini recente » Cod sursa (job #649670) | Cod sursa (job #3208796) | Cod sursa (job #37058) | Borderou de evaluare (job #3248045) | Cod sursa (job #191149)
Cod sursa(job #191149)
#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;
}