真的绷不住了,卡了一天没过,大佬帮忙看看吧
查看原帖
真的绷不住了,卡了一天没过,大佬帮忙看看吧
1217330
xdedb楼主2024/1/6 10:44

样例是可以过的,实在找不到问题在哪了,初学搜索,大佬们帮帮忙吧

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

double des;
double the;

void dfs(int last,int num,int to,int * arr);

int main(){
    int s[4];
    int ans=0;
    for(int i=0;i<4;i++){
        cin>>s[i];
    }
    for(int i=0;i<4;i++){
        the=19260814;
        int tn,tol=0;
        tn=s[i];
        int time[tn];
        for(int t=0;t<tn;t++){
            cin>>time[t];
            tol+=time[t];
        }
        sort(time,time+tn);
        des=(double)tol/2;
        dfs(0,-1,tn,time);
        ans+=the;
    }
    cout<<ans;
}

void dfs(int last,int num,int to,int * arr){
    int la=last;
    for(int i=num+1;i<to;i++){
        la=last+arr[i];
        if(la<des){
            dfs(la,i,to,arr);
        }else{
            if(la<the){
                the=la;
                return;
            }
        }
    }
}
2024/1/6 10:44
加载中...