本文主要是介绍叠放书籍~~,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
void stackBook(string books)
{
vector<vector<int>> arr;
char str[books.size() + 1];
strcpy(str, books.c_str());
char* p = strtok(str, "[],");
while(p != NULL)
{
vector<int> temp;
temp.push_back(stoi(p));
p = strtok(NULL, "[],");
temp.push_back(stoi(p));
arr.push_back(temp);
p = strtok(NULL, "[],");
}
sort(arr.begin(), arr.end(), [](const vector<int>& a, const vector<int>& b)
{
if(a[0] != b[0])
{
return a[0] < b[0];
}
else
{
return a[1] < b[1];
}
});
int len = arr.size();
vector<int> dp(len, 1);
int result = 1;
for(int i = 1; i < len; i++)
{
vector<int> cur = arr[i];
for(int j = 0; j < i; j++)
{
vector<int> pre = arr[j];
if(cur[0] > pre[0] && cur[1] > pre[1])
{
dp[i] = max(dp[i], dp[j] + 1);
}
result = max(result, dp[i]);
}
}
cout << result << endl;
}
int main()
{
stackBook("[[20,16],[15,11],[10,10],[9,9]]");
return 0;
}
这篇关于叠放书籍~~的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!