Matrix
Time Limit: 2000MS   Memory Limit: 30000K
Total Submissions: 3845   Accepted: 1993

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 题意:一个矩阵经过变换之后(变换规则如上图),每次都有一个每一列的最大值,现在求解所有的这些变换中最大值的最小值。
题解:最多7^7。。所以深搜。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<iostream>
using namespace std;
const int INF = ;
int M[][];
int n,res; int now(){
int MAX = -INF;
for(int i=;i<=n;i++){
int sum = ;
for(int j=;j<=n;j++){
sum=sum+M[j][i];
}
if(sum>MAX) MAX = sum;
}
return MAX;
}
void _move(int k){ ///移动第k行
int temp = M[k][n];
for(int i=n;i>;i--){
M[k][i] = M[k][i-];
}
M[k][] = temp;
}
void dfs(int step){ ///当前移动第step行
if(step==n+) {
return;
}
int MAX = now();
if(MAX<res) res = MAX;
for(int i=;i<=n;i++){ #移动 n 次枚举该行移动的所有状态
_move(step);
dfs(step+);
}
} int main()
{
while(scanf("%d",&n)!=EOF,n!=-){
res = INF;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
scanf("%d",&M[i][j]);
}
}
dfs();
printf("%d\n",res);
}
return ;
}

hdu 2078(DFS)的更多相关文章

  1. HDU 5143 DFS

    分别给出1,2,3,4   a, b, c,d个 问能否组成数个长度不小于3的等差数列. 首先数量存在大于3的可以直接拿掉,那么可以先判是否都是0或大于3的 然后直接DFS就行了,但是还是要注意先判合 ...

  2. Snacks HDU 5692 dfs序列+线段树

    Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...

  3. HDU 5877 dfs+ 线段树(或+树状树组)

    1.HDU 5877  Weak Pair 2.总结:有多种做法,这里写了dfs+线段树(或+树状树组),还可用主席树或平衡树,但还不会这两个 3.思路:利用dfs遍历子节点,同时对于每个子节点au, ...

  4. hdu 4751(dfs染色)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4751 思路:构建新图,对于那些两点连双向边的,忽略,然后其余的都连双向边,于是在新图中,连边的点是能不 ...

  5. HDU 1045 (DFS搜索)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1045 题目大意:在不是X的地方放O,所有O在没有隔板情况下不能对视(横行和数列),问最多可以放多少个 ...

  6. HDU 1241 (DFS搜索+染色)

    题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=1241 题目大意:求一张地图里的连通块.注意可以斜着连通. 解题思路: 八个方向dfs一遍,一边df ...

  7. HDU 1010 (DFS搜索+奇偶剪枝)

    题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意:给定起点和终点,问刚好在t步时能否到达终点. 解题思路: 4个剪枝. ①dep&g ...

  8. hdu 1716(dfs)

    题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=1716     排列2   Problem Description Ray又对数字的列产生了兴趣:现 ...

  9. hdu 4705 dfs统计更新节点信息

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4705 #pragma comment(linker, "/STACK:16777216&qu ...

随机推荐

  1. 简单的C++ DLL注入

    今天呢,我们来讨论一下用C++实现DLL注入的简单方法. 环境: Visual Studio 2015及以上 Windows 7及以上 入门需要了解的: DLL是什么:DLL_360百科 DLL是Dy ...

  2. pandas的数据联级

    一.索引的堆(stack) 1.行列的转化: Stack():列转行 Unstack():行转列 Stack对应行, 使用小技巧:使用stack()的时候,level等于哪一个,哪一个就消失,出现在行 ...

  3. jmeter操作mysql数据库

    1.导入jdbc的jar包,因为jmeter本身不能直接连接mysql,所以需要导入第三方的jar包,来连接mysql 2.创建数据库连接配置,mysql的url.端口号.账号.密码 在JDBC Co ...

  4. OpenCV中图像的读取,显示与保存

      图像的读取,显示与保存 相关函数:cv2.imread().cv2.imshow().cv2.imwrite() 1.读入图像: 用cv2.imread()函数来读取图像,cv2.imread(路 ...

  5. Python之简单Socket编程

    Socket编程这块儿还是比较重要的,记录一下:实现服务器端和客户端通信(客户端发送系统指令,如ipconfig等,服务器端执行该指令,然后将指令返回结果给客户端再传过去,设置一次最多直接收1024字 ...

  6. HDU 4348 To the moon 主席树

    题意: 给出一个长度为\(n(n \leq 10^5)\)的序列,最开始时间\(t=0\),支持下面几个操作: \(C \, l \, r \, d\):将区间\([l,r]\)每个数都加上\(d\) ...

  7. UVa 579 Clock Hands

    水题.. 求任意时刻时针和分针的夹角,其结果在0°到180°之间. 这里又一次用到了sscanf()函数,确实很方便. 思路:我们分别求出时针和分针转过的角度,然后大的减小的,如果结果ans大于180 ...

  8. MySQL常见数据库引擎及比较?

    一:MySQL存储引擎简介 MySQL有多种存储引擎,每种存储引擎有各自的优缺点,大家可以择优选择使用:MyISAM.InnoDB.MERGE.MEMORY(HEAP).BDB(BerkeleyDB) ...

  9. 缓存淘汰算法之LRU实现

    Java中最简单的LRU算法实现,就是利用 LinkedHashMap,覆写其中的removeEldestEntry(Map.Entry)方法即可 如果你去看LinkedHashMap的源码可知,LR ...

  10. Django底层原理简介与安装

    Django环境目录搭建一栏: 利用wsgiref模块封装好的socket搭建服务端: #利用wsgiref模块封装好的socket演示操作(例如accept\recv) #也可以实现socket服务 ...