Cod sursa(job #1767775)

Utilizator ade_tomiEnache Adelina ade_tomi Data 29 septembrie 2016 18:49:09
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.35 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <stdio.h>
#define NMAX 3505
using namespace std;
short aib[NMAX][NMAX];
struct str
{
    short a, b, c;
};
str v[NMAX + 2];
short  lsb (short x)
{
    return x & (-x);
}
void update (short x, short y, short val)
{
    while (x <= NMAX)
    {
        short  y1 = y;
        while (y1 <= NMAX)
        {
            aib[x][y1] = max (aib[x][y1], val);
            y1 += lsb (y1);
        }
        x += lsb (x);
    }
}
short query (short x, short y)
{
    short sol = 0;
    while (x > 0)
    {
        short y1 = y;
        while (y1 > 0)
        {
            sol = max (sol, aib[x][y1]);
            y1 -= lsb (y1);
        }
        x-= lsb(x);
    }
    return sol;
}
bool cmp (str aa, str bb)
{
    return aa.a < bb.a;

}
int main ()
{
    short T,n;
    ifstream cin ("cutii.in");
    ofstream cout ("cutii.out");
    cin >> n >> T;
    while (T)
    {
        memset (aib, 0, sizeof(aib));
        T--;
        short sol = 0;
        for (short i = 1;i <= n; i++)
            cin >> v[i].a >> v[i].b >> v[i].c;
        sort (v + 1, v + 1 + n, cmp);
        short db = 1;
        for (short i = 1; i <= n; i++)
        {
           short q = query (v[i].b , v[i].c );
           update (v[i].b, v[i].c, q + 1);
            
        }
        cout << query(n,n) << "\n";
    }
    return 0;
}