UVA_497_Strategic Defense Initiative

#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#pragma warning(disable:4996)
using std::cin;
using std::cout;
using std::endl;
using std::stringstream;
using std::string;
using std::vector;
using std::list;
using std::pair;
using std::set;
using std::multiset;
using std::map;
using std::multimap;
using std::stack;
using std::queue;
using std::priority_queue;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int T;
	while (cin >> T)
	{
		cin.get();//屏蔽回车
		cin.get();//屏蔽回车
		while (T--)
		{
			string str;
			vector<vector<int>>dp;
			while (getline(cin, str))
			{
				if (str.empty())
				{
					break;
				}
				stringstream stream; stream << str;
				int value; stream >> value;
				dp.resize(dp.size() + 1);
				dp[dp.size() - 1].push_back(value);
			}
			int index = 0;
			for (size_t i = 1; i != dp.size(); i++)
			{
				int value = dp[i][0];
				for (int j = i - 1; j >= 0; j--)
				{
					if (value > dp[j][dp[j].size() - 1] && dp[i].size() < dp[j].size() + 1)
					{
						dp[i] = dp[j];
					}
				}
				if (dp[i][0] != value)
				{
					dp[i].push_back(value);
				}
				if (dp[i].size() > dp[index].size())
				{
					index = i;
				}
			}
			cout << "Max hits: " << dp[index].size() << endl;
			for (size_t i = 0; i < dp[index].size(); i++)
			{
				cout << dp[index][i] << endl;
			}
			if (T)
			{
				cout << endl;
			}
		}
	}
	return 0;
}

你可能感兴趣的:(dynamic,programming,uva,LIS)