捞Why
查看原帖
捞Why
421904
探索者ONGO楼主2024/9/17 11:38
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+7;
const int INF=1e5+7;
const bool LE=1;
const bool RI=0;
const bool ltor=1;
const bool rtol=0;
int n,hour[N];
bool pos[N];
int go(bool stage){
    int num,tmp,ans;
    if(stage==rtol){
        num=0;
        ans=0;
        for(int i=1;i<=n;i++){
            if (pos[i]==RI) {
                num++;
                if(hour[i]>ans) ans=hour[i];
            }
        }
        if(num<=2) return ans;
        ans=INF;
        for(int i=1;i<=n-1;i++){
            if(pos[i]==RI){
                for (int j = i + 1; j <= n; j++){
                    if (pos[j]==RI) {
                        pos[i]=LE;
                        pos[j]=LE;
                        tmp=max(hour[i],hour[j])+go(ltor);
                        if (tmp<ans) ans=tmp;
                        pos[i]=RI;
                        pos[j]=RI;
                    }
                }
            }
        }
        return ans;
    }
    if(stage==ltor){
        ans=INF;
        for(int i=1;i<=n;i++){
            if(pos[i]==LE) {
                pos[i]=RI;
                tmp=hour[i]+go(rtol);
                if (tmp<ans) ans=tmp;
                pos[i]=LE;
            }
        }
        return ans;
    }
    return 0;
}

signed main(){
    scanf("%lld",&n);
    for (int i=1;i<=n;i++){
        scanf("%lld",&hour[i]);
        pos[i]=RI;
    }
    printf("%lld\n",go(rtol));
    return 0;
}

为什么只有10分??

2024/9/17 11:38
加载中...