#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;
}
UVA_497_Strategic Defense Initiative
最新推荐文章于 2020-04-03 23:40:44 发布
本文介绍了一个使用C++实现的最长递增子序列(LIS)算法案例,该算法通过读取一系列整数并找出其中最长的递增子序列。通过对输入数据的逐行解析,算法构建了动态规划表来跟踪递增子序列的状态,最终输出最长递增子序列的长度及其具体数值。
1121

被折叠的 条评论
为什么被折叠?



