文章
8
粉丝
27
获赞
24
访问
727
输入
9
1 9 4 3 5 3 2 1 10
0 1 2 3 4 5 6 7 8 //下标
1 1 2 3 2 3 4 5 2 //dp
-1 -1 1 2 1 2 3 6 -1 //pre
从最大dp的5开始,对应数字1。pre为6,找到下标6对应数字2。下标6pre为3,找到下标3对应数字3。下标3pre为2,找到下标2对应数字4。下标2pre为1,找到下标1对应数字9。
下标1pre为-1,回溯终止。
用数组倒着存上面找到的对应数字,再正序输出
9 4 3 2 1
#include <bits/stdc++.h>
using namespace std;
int x;
int main() {
while(cin>>x){
vector<int>y(x);
for(int i=0;i<x;i++)
cin>>y[i];
vector<int>dp(x,1);
int big=0,current=0;
vector<int>pre(x,-1);//记录前驱,全设置为-1,之后后面有效的位置会被赋值,即使第一个数字就是最大的,
 ...
登录后发布评论
暂无评论,来抢沙发