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. [游戏学习27] MFC 匀速运动

    >_<:理解上一个时间函数的概念和用法,本节的实现也比较简单 >_<:就是简单的绘图+时间函数 >_<:TicTac.h #define EX 1 //该点左鼠标 ...

  2. spring mvc ajax 提交复杂数组类型

    The server refused this request because the request entity is in a format not supported by the reque ...

  3. java基础接口练习

    1.编写2个接口:InterfaceA和InterfaceB:在接口InterfaceA中有个方法voidprintCapitalLetter():在接口InterfaceB中有个方法void pri ...

  4. static/final

  5. Liferay7 BPM门户开发之27: MVC Portlet插件工程开发

    官网上的教材说实话实在精简不清晰. https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/creating-an-mvc-por ...

  6. bzoj 1207: [HNOI2004]打鼹鼠

    1207: [HNOI2004]打鼹鼠 Time Limit: 10 Sec  Memory Limit: 162 MB Description 鼹鼠是一种很喜欢挖洞的动物,但每过一定的时间,它还是喜 ...

  7. Redis & Python/Django 简单用户登陆

    一.Redis key相关操作: 1.del key [key..] 删除一个或多个key,如果不存在则忽略 2.keys pattern keys模式匹配,符合glob风格通配符,glob风格的通配 ...

  8. quartzScheduler_Worker-1] but has failed to stop it. This is very likely to create a memory leak解决

    01-Jul-2016 07:24:20.218 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 80 ...

  9. ThinkBox DOC

    插件源码下载 @github https://github.com/Aoiujz/ThinkBox.git 插件使用方法 引入文件 //使用ThinkBox弹出框必须引入以上三个文件. //jQuer ...

  10. 黄页js-sdk开发总结分享

    2014年,为了方便第三方开发者能够调用本地的一些功能,我们提供了一套js-sdk.通过调用我们的接口,开发者可以定制UI,获取当前的手机状态,调用支付,黄页扫一扫功能,为用户提供更加优质的体验.下面 ...