将绝对值拆开,无非是32种情况,对于x1,x2,x3,x4,x5
如果取值为10011的话,那么y1,y2,y3,y4,y5的取值必然是01100,那么只要保存每个状态的最大值,最后求其互补状态的最大值就行了
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <sstream>
#define LL long long
#define INF 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-6
const int maxn = 100000 + 5;
using namespace std;
double a[maxn][5];
double state[1<<6];
int main(){
int n;
while(scanf("%d",&n) == 1 && n){
memset(state, -INF, sizeof(state));
for(int i=0; i<n; i++){
for(int j=0; j<5; j++)
scanf("%lf",&a[i][j]);
}
for(int i=0; i<n; i++){
for(int j=0; j<(1<<5); j++){
double ans = 0;
for(int k=0; k<5; k++){
if((1<<k) & j){
ans += a[i][k];
}
else ans -= a[i][k];
}
state[j] = max(state[j], ans);
}
}
double ans = 0;
for(int i=0; i<(1<<5); i++){
int c = (1<<5)-i-1;
ans = max(ans, state[i] + state[c]);
}
printf("%.2lf\n",ans);
}
}