Forrest


私信TA

用户名:dotcpp0717441

访问量:1832

签 名:

等  级
排  名 142
经  验 7204
参赛次数 1
文章发表 80
年  龄 0
在职情况 教师
学  校 优学乐程
专  业

  自我简介:

解题思路:后续补充

注意事项:测试结果顺序可能不一致,交换a, b序列嵌套循环

参考代码:

#include#include#include 
#includeusing namespace std;
const int N = 5e2 + 10;
struct node{
	int v = 0;
	vector p;
};
int a[N],b[N],n,m;
node f[N];
int main()
{
	cin >> n;
	for(int i = 1; i > a[i];
	cin >> m;
	for(int i = 1; i > b[i];

	for(int i = 1; i <= m; i ++){
		node mx;
		for(int j = 1; j  a[j])  {
					if(mx.v < f[j].v) mx = f[j];
				}
				else if(b[i] == a[j]) {
					f[j].v = mx.v + 1;
					f[j].p = mx.p;
					f[j].p.push_back(a[j]);
				}
		}
	}
	int ans = 0,res = 0;  
    for(int j = 1; j <= n; j ++) {
    	if(ans < f[j].v){
    		ans = f[j].v;
    		res = j;
		}
	}
    cout << ans << endl;
    for(auto it = f[res].p.begin(); it != f[res].p.end(); it++ )
    	cout << *it << ' ';
	return 0;
}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区