|
沙发
楼主 |
发表于 2018-10-5 12:04:16
|
只看该作者
- #include<iostream>
- #include<cstdlib>
- #define FOR(i,a,b) for(register int i=a;i<=b;i++)
- #define ROF(i,a,b) for(register int i=a;i>=b;i--)
- using namespace std;
- const int N=70;
- int n,l[N],len,temp,minn=0x7fff,maxn;
- void dfs(int e,int sum,int res,int p)
- {
- if(!res)
- {
- cout<<e<<endl;
- exit(0);
- }
- if(sum==e)
- {
- dfs(e,0,res-1,maxn);
- return;
- }
- ROF(i,p,minn)
- {
- if(l[i] && i+sum<=e)
- {
- l[i]--;
- dfs(e,sum+i,res,i);
- l[i]++;
- if(sum==0 || sum + i==e)break;
- }
- }
- return;
- }
- int main()
- {
- cin>>n;
- FOR(i,1,n)
- {
- cin>>temp;
- if(temp>50)continue;
- l[temp]++;len+=temp;
- minn=min(minn,temp);
- maxn=max(maxn,temp);
- }
- temp=len>>1;
- FOR(i,maxn,temp)
- if(len%i==0)dfs(i,0,len/i,maxn);
- cout<<len<<endl;
- return 0;
- }
复制代码 |
|