Matrix
Time Limit: 2000MS   Memory Limit: 30000K
Total Submissions: 3239   Accepted: 1680

Description

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 
max0<=j< n{Cj|Cj=Σ0<=i< nAi,j}

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
题目大意:一个矩阵每一行的元素都可以循环右移,每次移动后求每个矩阵每一列的和的最大值,然后求所有这些最大值中的最小值。
解题方法:直接暴搜,没啥技巧可言。
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std; int ans = 0x7fffffff; void Shift(int row, int n, int matrix[][])
{
int temp = matrix[row][n - ];
for (int i = n - ; i > ; i--)
{
matrix[row][i] = matrix[row][i - ];
}
matrix[row][] = temp;
} void DFS(int index, int n, int matrix[][])
{
if (index == n)
{
return;
}
int maxsum = -;
for (int i = ; i < n; i++)
{
int sum = ;
for (int j = ; j < n; j++)
{
sum += matrix[j][i];
}
if (sum > maxsum)
{
maxsum = sum;
}
}
if (maxsum < ans)
{
ans = maxsum;
}
for (int i = ; i < n; i++)
{
Shift(index, n, matrix);
DFS(index + , n, matrix);
}
} int main()
{
int n;
int matrix[][];
while(scanf("%d", &n) != EOF && n != -)
{
ans = 0x7fffffff;
for (int i = ; i < n; i++)
{
for (int j = ; j < n; j++)
{
scanf("%d", &matrix[i][j]);
}
}
DFS(, n, matrix);
printf("%d\n", ans);
}
return ;
}

POJ 2078 Matrix的更多相关文章

  1. POJ poj 2155 Matrix

    题目链接[http://poj.org/problem?id=2155] /* poj 2155 Matrix 题意:矩阵加减,单点求和 二维线段树,矩阵加减,单点求和. */ using names ...

  2. 矩阵十点【两】 poj 1575 Tr A poj 3233 Matrix Power Series

    poj 1575  Tr A 主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1575 题目大意:A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的 ...

  3. 【POJ - 2078】Matrix(dfs)

    -->Matrix Descriptions: 输入一个n×n的矩阵,可以对矩阵的每行进行任意次的循环右移操作,行的每一次右移后,计算矩阵中每一列的和的最大值,输出这些最大值中的最小值. Sam ...

  4. POJ 2155 Matrix

    二维树状数组....                          Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissio ...

  5. poj 2155:Matrix(二维线段树,矩阵取反,好题)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17880   Accepted: 6709 Descripti ...

  6. POJ 2155 Matrix (二维线段树)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17226   Accepted: 6461 Descripti ...

  7. poj 3685 Matrix(二分搜索之查找第k大的值)

    Description Given a N × N matrix A, whose element × i + j2 - × j + i × j, you are to find the M-th s ...

  8. POJ 2155 Matrix (D区段树)

    http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 1 ...

  9. POJ 3233 Matrix Power Series(矩阵高速功率+二分法)

    职务地址:POJ 3233 题目大意:给定矩阵A,求A + A^2 + A^3 + - + A^k的结果(两个矩阵相加就是相应位置分别相加).输出的数据mod m. k<=10^9.     这 ...

随机推荐

  1. [C++] socket -7 [邮槽]

    ::利用邮槽实现windons进程通信 ::一般情况下CreateMailslot()常被使用在进程通信的服务器上,在客户端则是用函数CreateFile()打开指定的邮槽之后进行相关的操作. ::将 ...

  2. 使用TabBarController(代码实现)

    step01:使用Xcode创建一个项目 step02:填写项目必要信息 step03:检查文件结构树是否正确 step04:创建一些类,这些类将会在后面用到!(选择Swift File) step0 ...

  3. paip.java swt 乱码问题解决

    paip.java swt 乱码问题解决 看累挂,Dfile.encoding是gbk的.. 作者Attilax  艾龙,  EMAIL:1466519819@qq.com  来源:attilax的专 ...

  4. paip.抓取网页内容--java php python

    paip.抓取网页内容--java php python.txt 作者Attilax  艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog ...

  5. iOS开发-迭代器模式

    迭代器模式(Iterator),提供一种方法顺序访问一个聚合对象中的各种元素,而又不暴露该对象的内部表示.开发过程中,我们可能需要针对不同的需求,可能需要以不同的方式来遍历整个整合对象,但是我们不希望 ...

  6. javaweb学习总结(二十三)——jsp自定义标签开发入门

    一.自定义标签的作用 自定义标签主要用于移除Jsp页面中的java代码. 二.自定义标签开发和使用 2.1.自定义标签开发步骤 1.编写一个实现Tag接口的Java类(标签处理器类) 1 packag ...

  7. Struts2学习笔记-基本结构

    一个普通的的web应用文件结构如下: 1. 最上层是应用名,区分大小写,在浏览器输入应用名的时候,必须与应用名的大小一样,例如:localhost:8080/HelloWorld 2. 在应用下,放有 ...

  8. Liferay7 BPM门户开发之35: AssetTag的集成查询

    Tag是liferay中的Asset特性,可以用来对信息进行分类,在iferay中的Asset类型为: 1. Web Content(自定义内容) 2. Documents and Media(文档库 ...

  9. Windows Server 2012 如何实现多个用户远程桌面登陆?

    Windows Server 2012 如何实现多个用户远程桌面登陆?说明:Windows Server 2012默认情况下,只运行2个用户远程桌面登陆,这里我们可以通过安装远程桌面会话主机配置来实现 ...

  10. 在 Xen 虚拟机下修改系统当前时间

    在 Xen 虚拟机下修改系统当前时间 Xen 虚拟机默认不允许不同的虚拟机使用不同的系统时间,因此所有虚拟机的系统时间都会同宿主机的系统时间严格同步,用 date 命令修改虚拟机系统时间时虽然提示成功 ...