跳到正文

个人记录

Code

Momoi_Saiba约 2 分钟
原文

这是 2026年10月29日 存档的第 6 版,不是当前版本。查看当前版本

文章信息与版本
C++
#include <bits/stdc++.h>
#define int long long
#define fr first
#define se second
#define vt vector
#define pii pair<int,int>
#define mkp make_pair
#define pb push_back
#define endl '\n'
#define I_am_a_furry return
using namespace std;
inline int read(){
	int x=0,f=1;
	int c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+(c-'0');
		c=getchar();
	}
	return x*f;
}
const int inf=INT_MAX;

const int N=20+7;
int c[N]={0};
int n,ma=0;
int v[N]={0};
int count(int x,int n){
    for(int i=n;i>=1;i--) if(c[i]==x) return i;
    return -1;
}
void dfs(int st){
    if(st==n+1){
        int s=0;
        for(int i=1;i<=n;i++){
            int index=count(c[i],i);
            if(index!=-1) s+=v[index];
        }
        ma=max(ma,s);
        I_am_a_furry;
    }
    bool f=c[st];
    c[st]=!f;
    dfs(st+1);
    c[st]=f;
    dfs(st+1);
}
void solve(){
    n=read();
    for(int i=1;i<=n;i++) v[i]=read();
    dfs(1);
    cout << ma << endl;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=read();
    while(t--) solve();
	I_am_a_furry 0;
}