Matrix


Time Limit: 2 Seconds      Memory Limit: 65536 KB


Given an n*n matrix A, whose entries Ai,j are integer numbers ( 0 <= i < n, 0 <= j < n ). An operation SHIFT at row i ( 0 <= i < n ) will move the integers in the row one position
right, and the rightmost integer will wrap around to the leftmost column.

You can do the SHIFT operation at arbitrary row, and as many times as you like. Your task is to minimize

Input

The input consists of several test cases. The first line of each test case contains an integer n. Each of the following n lines contains n integers, indicating the matrix A. The input
is terminated by a single line with an integer -1. You may assume that 1 <= n <= 7 and |Ai,j| < 104.

Output

For each test case, print a line containing the minimum value of the maximum of column sums.

Sample Input

2

4 6

3 7

3

1 2 3

4 5 6

7 8 9

-1

Sample Output

11

15


Source: Asia 2004, Shanghai (Mainland China), Preliminary

————————————————————————————————————

题目的意思是每一行可以任意移动求每列和的最大值的最小值

暴力DFS枚举行与行之间关系,可以开一个数组A保存每一行第一个数位置效率n^(n-1),求最小n^2 ,总共n^(n+1)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <functional>
#include <bitset>
#include <string> using namespace std; #define LL long long
#define INF 0x3f3f3f3f int a[10][10];
int ans[10];
int n,mn; void dfs(int x)
{
if(x==n)
{
int mx=-1;
for(int i=0; i<n; i++)
{
int ans1=0;
for(int j=0; j<n; j++)
{
int pos=ans[j]+i;
if(pos>=n) pos-=n;
ans1+=a[j][pos];
}
mx=max(ans1,mx); }
mn=min(mn,mx);
return;
}
for(int i=0; i<n; i++)
{
ans[x]=i;
dfs(x+1);
}
} int main()
{
while(~scanf("%d",&n))
{
if(n==-1)
break;
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
scanf("%d",&a[i][j]);
mn=INF;
ans[0]=0;
dfs(1);
printf("%d\n",mn);
} return 0;
}

ZOJ2418 Matrix 2017-04-18 21:05 73人阅读 评论(0) 收藏的更多相关文章

  1. HDU6023 Automatic Judge 2017-05-07 18:30 73人阅读 评论(0) 收藏

    Automatic Judge Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  2. Run Loop简介 分类: ios技术 ios相关 2015-03-11 22:21 73人阅读 评论(0) 收藏

    做了一年多的IOS开发,对IOS和Objective-C深层次的了解还十分有限,大多还停留在会用API的级别,这是件挺可悲的事情.想学好一门语言还是需要深层次的了解它,这样才能在使用的时候得心应手,出 ...

  3. 博弈论入门小结 分类: ACM TYPE 2014-08-31 10:15 73人阅读 评论(0) 收藏

    文章原地址:http://blog.csdn.net/zhangxiang0125/article/details/6174639 博弈论:是二人或多人在平等的对局中各自利用对方的策略变换自己的对抗策 ...

  4. 基于ArcGIS for Server的服务部署分析 分类: ArcGIS for server 云计算 2015-07-26 21:28 11人阅读 评论(0) 收藏

    谨以此纪念去年在学海争锋上的演讲. ---------------------------------------------------- 基于ArcGIS for Server的服务部署分析 -- ...

  5. windows server 2008 R2域中的DC部署 分类: AD域 Windows服务 2015-06-06 21:09 68人阅读 评论(0) 收藏

    整个晚上脑子都有点呆滞,想起申请注册好的博客还从来都不曾打理,上来添添生机.从哪里讲起呢,去年有那么一段时间整个人就陷在域里拔不出来,于是整理了一些文档,害怕自己糊里糊涂的脑子将这些东西会在一觉醒来全 ...

  6. 基于命令行编译打包phonegap for android应用 分类: Android Phonegap 2015-05-10 10:33 73人阅读 评论(0) 收藏

    也许你习惯了使用Eclipse编译和打包Android应用.不过,对于使用html5+js开发的phonegap应用,本文建议你抛弃Eclipse,改为使用命令行模式,绝对的快速和方便. 一直以来,E ...

  7. 哈夫曼树-Fence Repair 分类: 树 POJ 2015-08-05 21:25 2人阅读 评论(0) 收藏

    Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 32424 Accepted: 10417 Descri ...

  8. Maya Calendar 分类: POJ 2015-06-11 21:44 12人阅读 评论(0) 收藏

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 70016   Accepted: 21547 D ...

  9. shell入门之函数应用 分类: 学习笔记 linux ubuntu 2015-07-10 21:48 77人阅读 评论(0) 收藏

    最近在学习shell编程,文中若有错误的地方还望各位批评指正. 先来看一个简单的求和函数 #!/bin/bash #a test about function f_sum 7 8 function f ...

随机推荐

  1. CVE2016-8863libupnp缓冲区溢出漏洞原理分析及Poc

    1.libupnp问题分析: (1)问题简述: 根据客户给出的报告,通过设备安装的libupnp软件版本来判断,存在缓冲区溢出漏洞:CVE-2016-8863. (2)漏洞原理分析: 该漏洞发生在up ...

  2. Delphi 操作键盘按下和释放操作

    Unit Unit1; Interface Uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ...

  3. KKT条件的物理意义(转)

    最好的解释:https://www.quora.com/What-is-an-intuitive-explanation-of-the-KKT-conditions# 作者:卢健龙链接:https:/ ...

  4. Spring boot集成 MyBatis 通用Mapper

    配置 POM文件 <parent> <groupId>org.springframework.boot</groupId> <artifactId>sp ...

  5. eclispe 通过git向码云上传

    本文将介绍如何将本地的项目提交到开源中国上去,过程比较详细,实现起来很简单.由于自己也算是一个新手,所以没有做过多的解释,只是单纯的描述了该如何去做. 1.在开源中国上面新建一个空项目 到这里也就结束 ...

  6. 通过NBU还原数据库提示LINKING异常,无法恢复数据

    错误提示: 解决方法:

  7. SpringMVC中ApplicationContext中的配置文件的问题(No bean named 'sessionFactory' is defined 已解决)

    在一个SpringMVC项目中, 连着两天不管怎么搞都是一直在报错, 报的最多的就是一个 Servlet.service() for servlet [springDispatcherServlet] ...

  8. TZOJ 4007 The Siruseri Sports Stadium(区间贪心)

    描述 The bustling town of Siruseri has just one sports stadium. There are a number of schools, college ...

  9. 利用Python和webhook实现自动提交代码

    最近在为公司书写项目的api文档,计划利用码云的wiki管理整个项目,公司自有git作为项目内容依托,这样全员都可参与,而我定期向码云推送就可以了. 问题 根据需求遇见了这样一个问题:我每次从git上 ...

  10. [leetcode]721. Accounts Merge账户合并

    Given a list accounts, each element accounts[i] is a list of strings, where the first element accoun ...