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语言中的内存分配与释放

    C语言中的内存分配与释放 对C语言一直都是抱着学习的态度,很多都不懂,今天突然被问道C语言的内存分配问题,说了一些自己知道的,但感觉回答的并不完善,所以才有这篇笔记,总结一下C语言中内存分配的主要内容 ...

  2. Linux内存寻址

    我会尽力以最简洁清晰的思路来写这篇文章. 所谓内存寻址也就是从写在指令里的地址,转化为实际物理地址的过程.因为操作系统要兼顾许多东西,所以也就变得复杂. 逻辑地址 → 线性地址 → 物理地址 逻辑地址 ...

  3. Origin的图片导出问题

    很多会议投稿都会要求提交的pdf文件用的是type1字体,因为type1字体是矢量字体,无论怎么放大缩小都不会失真.一旦pdf里嵌入了其他非矢量字体,例如type3字体,就会通不过测试,一个典型的例子 ...

  4. Atitit.mvc的趋势与未来attilax总结

    Atitit.mvc的趋势与未来attilax总结 1. Mvc的分类 (服务端mvc  vs客户端mvc)1 2. Mvc的趋势,从服务端mvc正在转向客户端mvc1 2.1. 更加完善的分离..h ...

  5. Javascript函数的简单学习

    第九课函数的定义与调用1:函数的定义    语法格式    function 函数名(数据类型 参数1){//function是定义函数的关键字        方法体;//statements,用于实 ...

  6. C#/ASP.NET Xml多级数据读取

    <Data> <Project> <Item Id="51351132-59a7-4c0b-909d-51b89b1c3159" IsDefault= ...

  7. eclipse安装activiti工作流插件

    方式一:在有网络的情况下,安装流程设计器步骤如下: 1.点击eclipse上方工具栏的Help,选择Install New Software 2.弹出如下窗口,然后填写插件名称和安装地址 Name: ...

  8. How to programmatically new a java class which implements sepecified interface in eclipse plugin development

    http://w3facility.org/question/how-to-programmatically-new-a-java-class-which-implements-sepecified- ...

  9. [C] zlstdint(让VC、TC等编译器自动兼容C99的整数类型)V1.0。支持Turbo C++ 3等DOS下的编译器

    作者:zyl910 以前我曾为了让VC++等编译器支持C99的整数类型,便编写了c99int库来智能处理(http://www.cnblogs.com/zyl910/p/c99int_v102.htm ...

  10. [Aaronyang] 写给自己的WPF4.5 笔记22 [3d交互与动画 3/4]

    OK,前面我们的3d模型都比较囧啊,最近也看了一点ZAM了解了一下,大致至少可以做个简单的模型用来演示. 1.交互,动起来的思路 ①修改Model3D对象的变换 ②修改应用于ModelVisual3D ...