Thursday, June 2, 2011

231 - Testing the CATCHER


#include<iostream>
#include<vector>
#include<cstdio>
#define MAXINT 2134483647
using namespace std;

vector< int > Height,Width;
vector< int > Len,Length;

int LIS(int);

int main()
{
    int n,k=1,a,f=1;
    //freopen("in.txt","r",stdin);

    while(scanf("%d",&a)&&a>-1)
    {
        Height.push_back(MAXINT);
        Height.push_back(a);
        while(scanf("%d",&a)&&a>-1)
            Height.push_back(a);

        n = Height.size();
        a = LIS(n);

        if(!f)printf("\n");
            else f = 0;
        printf("Test #%d:\n  maximum possible interceptions: %d\n",k++,a);

        Height.clear();
    }
    return 0;
}

int LIS(int n)
{
    int i,k,tmp;
    Len = vector < int >(n);
    for(i=0;i<n;i++)
        Len[i] = 0;

    for(k = 1;k < n; k++)
    {
        for(i = k-1; i>=0; i--)
        {
            tmp = 1 + Len[i];
            if(Height[k] <= Height[i] && Len[k] < tmp)
                Len[k] = tmp;
        }
    }

    tmp = Len[1];
    for(i=2;i<n;i++)
        if(tmp < Len[i])
            tmp = Len[i];
    return tmp;
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.