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. [stm32] MPU6050 HMC5883 Kalman 融合算法移植

    一.卡尔曼滤波九轴融合算法stm32尝试 1.Kalman滤波文件[.h已经封装为结构体] /* Copyright (C) 2012 Kristian Lauszus, TKJ Electronic ...

  2. win系统下nodejs安装及环境配置

    第一步:下载安装文件下载nodejs,官网:http://nodejs.org/download/,我这里下载的是node-v0.10.28-x86.msi,如下图: 第二步:安装nodejs下载完成 ...

  3. LINQ-to-SQL那点事~LINQ-to-SQL中的并发冲突与应对

    回到目录 在上一篇文章中提到了并发冲突,还说详细的说明在这讲来说,呵呵,那现在就说一下吧! 并发冲突产生的原因 事实上,linq to sql中的并发冲突是指记录在进行update操作时,客户端A1取 ...

  4. [Java拾遗四]JavaWeb基础之Servlet_Request&&Response

    今天来回顾下之前学过Servle的Resquest以及Response的知识.1,Request和Response技术:    rr的作用:        request是请求,封装用户的请求信息.若 ...

  5. Atitit.web三大编程模型 Web Page Web Forms 和 MVC

    Atitit.web三大编程模型 Web Page    Web Forms 和 MVC 1. 编程模型是 Web Forms 和 MVC (Model, View, Controller). 2.  ...

  6. atitit.sql server2008导出导入数据库大的表格文件... oracle mysql

    atitit.sql server2008导出导入数据库大的表格文件... 1. 超过80M的文件是不能在查询分析器中执行的 1 2. Oracle ,mysql大的文件导入 1 2.1. 使用sql ...

  7. JAVA开发工具eclipse中@author怎么改

    1:JAVA开发工具eclipse中@author怎么改,开发的时候为了注明版权信息. 用eclipse开发工具默认的是系统用户,那么怎么修改呢 示例如图所示 首先打开Eclipse--->然后 ...

  8. Activiti 部署流程定义及相关的表(classpath部署、zip部署)

    package com.mycom.processDefinition; import org.activiti.engine.ProcessEngine; import org.activiti.e ...

  9. C#Winform程序如何发布并自动升级(图解)

    C#Winform程序如何发布并自动升级(图解)     有不少朋友问到C#Winform程序怎么样配置升级,怎么样打包,怎么样发布的,在这里我解释一下打包和发布 关于打包的大家可以看我的文章C# w ...

  10. Python:IOError: image file is truncated 的解决办法

    代码如下: #coding:utf-8 from PIL import Image import pytesseract def test(): im = Image.open(r"pic. ...