mahmoud-a
8/27/2017 - 4:40 PM

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=167

#include <bits/stdc++.h>

#define ll long long
#define sz(v) ((int) ((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define lp(i, n) for(int i = 0; i < (int)(n); ++i)
#define rep(i, v) for(int i = 0; i < sz(v); ++i)

using namespace std;

int n;
const int MAX = 1e4+5;
const int OO = 1e9;

int a[MAX];
int cache[MAX][35000];

int maxInter(int i, int pre) {
    if(i == n)
        return 0;
    int &ret = cache[i][pre];
    if(ret != -1)
        return ret;
    int ch1 = -1*OO;
    if(a[i] <= pre)
        ch1 = 1+maxInter(i+1, a[i]);
    int ch2 = maxInter(i+1, pre);

    return ret = max(ch1, ch2);
}


int main() {
    int t =1, x;
    while(cin>>x && x != -1) {
        clr(cache, -1);
        if(t!=1)
            cout << "\n";
        n = 0;
        a[n] = x;
        n++;
        while(cin>>x && x != -1) {
            a[n] = x;
            n++;
        }
        cout << "Test #" << t << ":\n  maximum possible interceptions: " << maxInter(0, 35000) << "\n";
        t++;
    }
    return 0;
}