ZOJ 2688 (最远曼哈顿距离)

将绝对值拆开,无非是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);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值