这个为什么567会T
查看原帖
这个为什么567会T
725327
chang_an_1029楼主2024/10/27 09:58
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],n,ans=-1,f[105][105][105];
void dfs(int st,int lst1,int lst2,int res){
	if(f[st][lst1][lst2]>res) return ;
	f[st][lst1][lst2]=res;
	if(st>n){
		ans=max(ans,res);
		return ;
	}
	if(lst1&&a[lst1]==a[st]) dfs(st+1,st,lst2,res+a[st]);//1
	else dfs(st+1,st,lst2,res);
	if(lst2&&a[lst2]==a[st]) dfs(st+1,lst1,st,res+a[st]);//2
	else dfs(st+1,lst1,st,res);
}
signed main(){
//	freopen("color.in","r",stdin);
//	freopen("color.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin>>T;
	while(T--){
		memset(f,0,sizeof f);
		ans=-1;
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i];
		if(n>100) return 0;
		dfs(1,0,0,0);
		cout<<ans<<'\n';
	}
	return 0;
}

2024/10/27 09:58
加载中...