Cod sursa(job #1325406)

Utilizator cautionPopescu Teodor caution Data 23 ianuarie 2015 21:44:16
Problema Cutii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.36 kb
#include <fstream>
#include <algorithm>
using namespace std;
struct box
{
    short x, y, z;
    long long vol;
    short no, max_so_far;
};
bool comp(box b1, box b2)
{
    if(b1.vol>b2.vol) return true;
    else return false;
}
int main()
{
    ifstream in("cutii.in");
    ofstream out("cutii.out");
    short n, t;
    box *boxes;
    in>>n>>t;
    boxes=new box[n];
    for(short i=1; i<=t; ++i)
    {
        for(short j=0; j<n; ++j)
        {
            in>>boxes[j].x>>boxes[j].y>>boxes[j].z;
            boxes[j].vol = boxes[j].x*boxes[j].y*boxes[j].z;
        }
        sort(boxes, boxes+n, comp);
        for(short i=0; i<n; ++i)
        {
            boxes[i].no=0;
            if(i)
                boxes[i].max_so_far=boxes[i-1].max_so_far;
            else boxes[i].max_so_far=0;
            for(short j=i-1; j>=0&&boxes[i].no<=boxes[j].max_so_far; --j)
            {
                if(boxes[i].x<boxes[j].x&&boxes[i].y<boxes[j].y&&boxes[i].z<boxes[j].z)
                {
                    if(boxes[i].no<=boxes[j].no)
                        boxes[i].no=boxes[j].no+1;
                    if(boxes[i].max_so_far<boxes[i].no)
                        boxes[i].max_so_far=boxes[i].no;
                }
            }
        }
        out<<boxes[n-1].max_so_far+1<<endl;
    }
    in.close(); out.close();
    return 0;
}