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. RabbitMQ(一) -- Hello world

    RabbitMQ -- Hello world RabbitMQ使用AMQP通信协议(AMQP是一个提供统一消息服务的应用层标准协议,基于此协议的客户端与消息中间件可传递消息,并不受客户端/中间件不同 ...

  2. Jenkins2 - 下载与启动

    文章来自:http://www.ciandcd.com 文中的代码来自可以从github下载: https://github.com/ciandcd 本文将引导jenkins初学者安装和配置jenki ...

  3. c++如何遍历删除map/vector里面的元素

    新技能Get! 问题 对于c++里面的容器, 我们可以使用iterator进行方便的遍历. 但是当我们通过iterator对vector/map等进行修改时, 我们就要小心了, 因为操作往往会导致it ...

  4. [iOS]The app icon set named "AppIcon" did not have any applicable content.

    Develop Tools: xCode 5.1 I write a demo for app settings feature. The tutorial url is here. When I a ...

  5. CSS扇形展开效果

    知识点预备: [1]CSS3中特别重要的transform中的rotate(),现在transform可以将元素进行2D和3D变形. 2D transform常用的transform-function ...

  6. paip.输入法编程---词库多意义条目分割 python实现.

    paip.输入法编程---词库多意义条目分割 python实现. ==========子标题 python mysql 数据库操作 多字符分隔,字符串分割 字符列表循环  作者 老哇的爪子 Attil ...

  7. asp.net时间 日期(DateTime) 的格式处理

    日期格式化{0:yyyy-MM-dd HH:mm:ss.fff}与{0:yyyy-MM-dd hh:mm:ss.fff}的区别 使用24小时制格式化日期:{0:yyyy-MM-dd HH:mm:ss. ...

  8. Leetcode 65 Valid Number 字符串处理

    由于老是更新简单题,我已经醉了,所以今天直接上一道通过率最低的题. 题意:判断字符串是否是一个合法的数字 定义有符号的数字是(n),无符号的数字是(un),有符号的兼容无符号的 合法的数字只有下列几种 ...

  9. Inno setup 安装*.inf文件_示例

    nno setup 调用*.Inf文件的条目区段名称_示例 首先自己编写一个INF文件来供 Inno setup 进行测试: ;复制以下代码到记事本然后另存为123.inf .然后把123.inf文件 ...

  10. Revit如何修改三维视图背景色

    Revit中默认的三维视图背景色为白色,有时候为了让现实效果更佳逼真,需要将三维视图背景色设置为天空色,只需在三维视图属性中打开"图形显示选项"即可对三维视图背景色进行设置.