Pagini recente » Cod sursa (job #84171) | Cod sursa (job #2198973) | Cod sursa (job #1020604) | Cod sursa (job #236888) | Cod sursa (job #66268)
Cod sursa(job #66268)
#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;
}