http://acm.hdu.edu.cn/showproblem.php?pid=4666

先看一个求曼哈顿的帖子http://www.cnblogs.com/lmnx/articles/2479747.html

然后用mulityset进行维护下就可以了

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<set>
using namespace std;
#define N 60010
int w[N][];
int main()
{
int i,j,q,g,k;
while(cin>>q>>k)
{
multiset<int>p[];
multiset<int>::iterator it;
for(g = ; g <= q ; g++)
{
int a;
scanf("%d",&a);
if(a==)
{
for(i =; i < k ; i++)
scanf("%d",&w[g][i]);
for(i = ; i < <<k ; i++)
{
int temp = ;
for(j = ; j < k ; j++)
{
if(i&(<<j))
temp+=w[g][j];
else
temp-=w[g][j];
}
p[i].insert(temp);
}
}
else
{
int x;
scanf("%d",&x);
for(i = ; i < <<k ; i++)
{
int temp=;
for(j = ; j < k ; j++)
{
if(i&(<<j))
temp+=w[x][j];
else
temp-=w[x][j];
}
it = p[i].find(temp);
p[i].erase(it);
}
}
int maxz=;
for(i = ; i < <<k ; i++)
{
j =(~i)&((<<k)-);
int t1,t2;
it = p[i].end();
it--;
t1 = (*it);
it = p[j].end();
it--;
t2 = (*it);
maxz = max(maxz,t1+t2);
}
cout<<maxz<<endl;
}
}
return ;
}

hdu4666Hyperspace的更多相关文章

随机推荐

  1. vs调试windows mobile程序时布署时间太长的解决办法

    vs调试windows mobile程序时布署时间太长的解决办法 1.VS平台上,选工具-选项-项目和解决方案-MS BUILD项目生成输出详细信息中选择“诊断”,目的是在调试窗口中看出哪个过程编译的 ...

  2. 使用FreeMarker生成静态HTML

    1.FreeMarker需要添加的Maven依赖: <dependency> <groupId>org.freemarker</groupId> <artif ...

  3. 用VIM写作

    Write in VIm 1.Writing in Vim by Dr. Bunsen

  4. Wix: Using Patch Creation Properties - Small Update

    Source Reference: wix help document  -- WiX Toolset License Using Patch Creation Properties  A patch ...

  5. [翻译][MVC 5 + EF 6] 6:创建更复杂的数据模型

    原文:Creating a More Complex Data Model for an ASP.NET MVC Application 前面的教程中,我们使用的是由三个实体组成的简单的数据模型.在本 ...

  6. MVC——分页控件

    不管是什么类型的网站,分页都是必不可少的功能实现.在这里记录一下我自己接触过的分页控件: 一. MvcPager控件(记得项目里添加MvcPager.dll的引用) 这里面比较常用的就 ——@Html ...

  7. php 二维转一维

    Array(    [0] => Array        (            [salesorderid] => 10001            [createdtime] =& ...

  8. Linux中的安装神器--yum源安装

    linux配置yum源 一.修改yum的配置文件     /etc/yum.repos.d/xxx.repo          1.进入yum配置文件目录        # cd /etc/yum.r ...

  9. 使用Class.getResource和ClassLoader.getResource方法获取文件路径

    自从转投Java阵营后,一直发下Java程序的路径读取异常麻烦,因此查阅了比较多的版本内容,整合了一份自己的学习笔记.主要使用Class及通过ClassLoader来动态获取文件路径. 查阅链接如下: ...

  10. vsftpd.conf配置详解

    根据 /etc/vsftpd/vsftpd.conf默认配置给出设定功能   # Example config file /etc/vsftpd/vsftpd.conf # The default c ...