2 条题解

  • 0
    @ 2023-10-8 20:19:22

    #include<bits/stdc++.h> #define ll long long using namespace std; ll read() { ll r=0,f=1;char c=getchar(); while((c<'0'||c>'9')&&(c!='-')) c=getchar(); if(c=='-') f=-1,c=getchar(); while(c>='0'&&c<='9') r=r10+c-'0',c=getchar(); return rf; } ll a[101],v[101],n,len,cnt; bool dfs(ll stick,ll cab,ll last) { if(stick>cnt) return true; if(cablen) return dfs(stick+1,0,1); ll failess=0; for(int i=last;i<=n;i++) if(!v[i]&&cab+a[i]<=len&&failess!=a[i]) { v[i]=1; if(dfs(stick,cab+a[i],i+1)) return true; failess=a[i]; v[i]=0; if(cab0||cab+a[i]==len) return false; } return false; } ll cmp(ll a,ll b) { return a>b; } int main() { // freopen("data.in","r",stdin); // freopen("data.out","w",stdout); n=read(); ll sum=0,val=0; for(int i=1;i<=n;i++) { ll b=read(); if(b>50) continue; a[i]=b; sum+=a[i]; val=max(val,a[i]); } sort(a+1,a+n+1,cmp); for(len=val;len<=sum;len++) { if(sum%len) continue; cnt=sum/len; memset(v,0,sizeof(v)); if(dfs(1,0,1)) break; } cout<<len<<endl; return 0; }

    信息

    ID
    1204
    时间
    1000ms
    内存
    512MiB
    难度
    8
    标签
    递交数
    12
    已通过
    9
    上传者