5-n的包包里面可以任意放0-2012个蘑菇
可以证明n<=3时都输出1024
然后枚举n==4 和n==5
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <cmath>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
typedef long long LL;
typedef long double LD;
#define pi acos(-1.0)
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
typedef pair<int, int> PI;
typedef pair<int, PI> PP;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int n,a[10],num[10];
while(scanf("%d",&n)!=EOF)
{
int sum=0;
memset(a,0,sizeof(a));
for(int i=0; i<5; i++) num[i]=i;
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
if(n<=3)
{
printf("1024\n");
continue;
}
else if(n==4)
{
int out=0;
do
{
int ans=0,x;
if(num[0]==4)
{
ans=sum-a[num[1]]-a[num[2]];
}
else if(num[1]==4)
{
ans=sum-a[num[0]]-a[num[2]];
}
else if(num[2]==4)
{
ans=sum-a[num[1]]-a[num[0]];
}
else
{
int x=a[num[0]]+a[num[1]]+a[num[2]];
if(x%1024!=0)
ans=0;
else ans=1024;
}
while(ans>1024) ans-=1024;
out=max(ans,out);
}
while(next_permutation(num,num+5));
cout<<out<<endl;
}
else
{
int out=0;
do
{
int ans=0;
int x=a[num[0]]+a[num[1]]+a[num[2]];
if(x%1024)
ans=0;
else ans=sum-x;
while(ans>1024) ans-=1024;
out=max(ans,out);
}
while(next_permutation(num,num+5));
cout<<out<<endl;
}
}
return 0;
}