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. windows下配置Nginx支持php

    编辑配置文件nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; ...

  2. 【linux】服务说明

     引用自<鸟哥的linux私房菜>  http://cn.linux.vbird.org/linux_server/0210network-secure_3.php 服务名称 服务内容 a ...

  3. 14-15.Yii2.0模型的创建/读取数据使用,框架防止sql注入

    目录 创建数据库 表article 配置 db.php 连接数据库 创建控制器 HomeController.php 创建models 创建数据库 表article 1.创建库表 CREATE TAB ...

  4. Manjaro 添加国内源和安装搜狗输入法

    Manjaro 系统虽然比 Ubuntu 用着稳定,但有些小地方没有 Ubuntu 人性化,比如默认安装完的系统貌似没有中国的,Ubuntu 估计是用的人多,所以安装完后会根据所在地给你配置更新的源. ...

  5. Java并发编程的艺术 记录(二)

    volatile的应用 volatile的定义如下:Java编程语言允许线程访问共享变量,为了确保共享变量能被准确和一致地更新,线程应该确保通过排他锁单独获得这个变量.Java语言提供了volatil ...

  6. LeetCode(165) Compare Version Numbers

    题目 Compare two version numbers version1 and version2. If version1 > version2 return 1, if version ...

  7. 水题:UVa213- Message Decoding

    Message Decoding Some message encoding schemes require that an encoded message be sent in two parts. ...

  8. 金阳光Android自动化测试第一季

    第一季:http://www.chuanke.com/v1983382-106000-218422.html 第一节:Android自动化预备课程基础(上)     1. 基于坐标点触屏:monkey ...

  9. Alpha版(内部测试版)发布

    首先通过微信扫吗下载我们的软件校园服务,首先进去登录界面没账号点击注册,注册完就可以登录了,进去界面我们在二手交易这项功能里我们即可以事卖家又可以是买家如果我们卖东西点击商品出售,填写商品信息,商品图 ...

  10. Eclipse下创建Spring MVC web程序--非maven版

    首先, 安装eclipse和tomcat, 这里我下载的是tomcat9.0版本64位免安装的:地址https://tomcat.apache.org/download-90.cgi 免安装的如何启动 ...