ZOJ3657
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4880
模拟题吧~~
一开始把题意理解错了,以为不知道都是0,然后就看不懂第一组样例,后来才明白那些是未知的,多少都可以。
英文啊~~~伤~~~
当n为0,1,2,3的时候一定可以达到最大;
当n等于4的时候单独考虑;
当n等于5的时候也单独考虑;
代码写的很不文艺,,,
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include <algorithm> 3 #include <math.h> 4 #include <cstdio> 5 using namespace std; 6 int a[10],b[10],sum; 7 bool check(int n){ 8 for(int i=0;i<n;i++) 9 for(int j=i+1;j<n;j++) 10 for(int k=j+1;k<n;k++){ 11 if( (a[i]+a[j]+a[k])==0 ){ 12 return 1; 13 } 14 } 15 for(int i=0;i<n;i++) 16 for(int j=i+1;j<n;j++) 17 for(int k=j+1;k<n;k++){ 18 if( (a[i]+a[j]+a[k])%1024==0 ){ 19 sum-=(a[i]+a[j]+a[k]); 20 return 1; 21 } 22 } 23 return 0; 24 } 25 int F(int x){ 26 if(x==0) return 0; 27 return (x%1024==0)?1024:(x%1024); 28 } 29 int main(){ 30 int n,res,top; 31 while(scanf("%d",&n)!=EOF){ 32 res=top=sum=0; 33 for(int i=0;i<n;i++){ 34 scanf("%d",&a[i]); 35 sum+=a[i]; 36 } 37 if(n<4) res=1024; 38 else if(n==4){ 39 if(check(n)){ 40 res=1024; 41 } 42 else{ 43 for(int i=0;i<4;i++) 44 for(int j=i+1;j<4;j++) 45 b[top++]=F(a[i]+a[j]); 46 sort(b,b+top); 47 res=b[top-1]; 48 } 49 } 50 else{ 51 if(check(n)){ 52 res=F(sum); 53 } 54 else res=0; 55 } 56 printf("%d\n",res); 57 } 58 return 0; 59 }