为啥拿不到23点的分
查看原帖
为啥拿不到23点的分
897873
lwthree楼主2024/11/24 14:10
#include <bits/stdc++.h>
using namespace std;
#define int long long

int a[6];
int ans;
int n;
void dfs(int x,int tot){
    // cout<<a[x]<<' '<<x<<' '<<tot<<endl;
    if (x==n&&a[x]==0){
        // cout<<"ans:"<<tot<<endl;
        ans=min(ans,tot);
        return;
    }
    if (a[x]==0){
        dfs(x+1,tot);
        return;
    }
    if (a[x]>=1){
        a[x]-=1;
        // cout<<"-1 ";
        dfs(x,tot+1);
        a[x]+=1;
    }
    if (a[x]>=1&&a[x+1]>=3){
        a[x]-=1;a[x+1]-=3;
        // cout<<"-1 -3 ";
        dfs(x,tot+1);
        a[x]+=1;a[x+1]+=3;
    }
    if (a[x]>=2){
        a[x]-=2;
        // cout<<"-2 ";
        dfs(x,tot+1);
        a[x]+=2;
    }
    if (a[x]>=3&&a[x+1]>=1){
        a[x]-=3;a[x+1]-=1;
        // cout<<"-3 -1 ";
        dfs(x,tot+1);
        a[x]+=3;a[x+1]+=1;
    }
    if (a[x]>=4){
        a[x]-=4;
        // cout<<"-4 ";
        dfs(x,tot+1);
        a[x]+=4;
    }

}

signed main(){
    // time_t begin=clock();
    // freopen("p1.in","r",stdin);
    // freopen("p1.out","w",stdout);
    ios::sync_with_stdio(0);cin.tie(0);
    int T;cin>>T;
    while (T--){
        ans=INT64_MAX;
        int ext=0;
        cin>>n;
        for (int i=1;i<=n;i++) {
            cin>>a[i];
            if (a[i]>=10){
                ext+=(a[i]-6)/4;
                a[i]-=(a[i]-6)/4*4;
            }
        }
        dfs(1,0);
        cout<<ans+ext<<"\n";
    }
    // time_t duration=clock()-begin;
    // cout<<"time="<<duration<<endl;
    return 0;
}
2024/11/24 14:10
加载中...