动态规划练习 12
题目:Testing the CATCHER (POJ 1887)
链接:http://acm.pku.edu.cn/JudgeOnline/problem?id=1887
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char **argv)
{
vector<int> data;
int idx = 0;
while (true)
{
int input;
cin >> input;
if (input == -1 && data.size() == 0)
{
break;
}
else if (input == -1)
{
vector<int> num(data.size());
int max = 0;
for (size_t i = 0; i < data.size(); ++i)
{
num[i] = 1;
for (size_t j = 0; j < i; ++j)
{
if (data[i] <= data[j] && num[j] + 1 > num[i])
{
num[i] = num[j] + 1;
}
}
if (num[i] > max) max = num[i];
}
cout << "Test #" << ++idx << ":" << endl;
cout << " maximum possible interceptions: " << max << endl;
cout << endl;
data.clear();
}
else
{
data.push_back(input);
}
}
return 0;
}