ZOJ2418 Matrix 2017-04-18 21:05 73人阅读 评论(0) 收藏
Matrix
Time Limit: 2 Seconds Memory Limit: 65536 KB
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
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
Source: Asia 2004, Shanghai (Mainland China), Preliminary
————————————————————————————————————
题目的意思是每一行可以任意移动求每列和的最大值的最小值
暴力DFS枚举行与行之间关系,可以开一个数组A保存每一行第一个数位置效率n^(n-1),求最小n^2 ,总共n^(n+1)
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- #include <algorithm>
- #include <queue>
- #include <set>
- #include <stack>
- #include <map>
- #include <functional>
- #include <bitset>
- #include <string>
- using namespace std;
- #define LL long long
- #define INF 0x3f3f3f3f
- int a[10][10];
- int ans[10];
- int n,mn;
- void dfs(int x)
- {
- if(x==n)
- {
- int mx=-1;
- for(int i=0; i<n; i++)
- {
- int ans1=0;
- for(int j=0; j<n; j++)
- {
- int pos=ans[j]+i;
- if(pos>=n) pos-=n;
- ans1+=a[j][pos];
- }
- mx=max(ans1,mx);
- }
- mn=min(mn,mx);
- return;
- }
- for(int i=0; i<n; i++)
- {
- ans[x]=i;
- dfs(x+1);
- }
- }
- int main()
- {
- while(~scanf("%d",&n))
- {
- if(n==-1)
- break;
- for(int i=0; i<n; i++)
- for(int j=0; j<n; j++)
- scanf("%d",&a[i][j]);
- mn=INF;
- ans[0]=0;
- dfs(1);
- printf("%d\n",mn);
- }
- return 0;
- }
ZOJ2418 Matrix 2017-04-18 21:05 73人阅读 评论(0) 收藏的更多相关文章
- HDU6023 Automatic Judge 2017-05-07 18:30 73人阅读 评论(0) 收藏
Automatic Judge Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- Run Loop简介 分类: ios技术 ios相关 2015-03-11 22:21 73人阅读 评论(0) 收藏
做了一年多的IOS开发,对IOS和Objective-C深层次的了解还十分有限,大多还停留在会用API的级别,这是件挺可悲的事情.想学好一门语言还是需要深层次的了解它,这样才能在使用的时候得心应手,出 ...
- 博弈论入门小结 分类: ACM TYPE 2014-08-31 10:15 73人阅读 评论(0) 收藏
文章原地址:http://blog.csdn.net/zhangxiang0125/article/details/6174639 博弈论:是二人或多人在平等的对局中各自利用对方的策略变换自己的对抗策 ...
- 基于ArcGIS for Server的服务部署分析 分类: ArcGIS for server 云计算 2015-07-26 21:28 11人阅读 评论(0) 收藏
谨以此纪念去年在学海争锋上的演讲. ---------------------------------------------------- 基于ArcGIS for Server的服务部署分析 -- ...
- windows server 2008 R2域中的DC部署 分类: AD域 Windows服务 2015-06-06 21:09 68人阅读 评论(0) 收藏
整个晚上脑子都有点呆滞,想起申请注册好的博客还从来都不曾打理,上来添添生机.从哪里讲起呢,去年有那么一段时间整个人就陷在域里拔不出来,于是整理了一些文档,害怕自己糊里糊涂的脑子将这些东西会在一觉醒来全 ...
- 基于命令行编译打包phonegap for android应用 分类: Android Phonegap 2015-05-10 10:33 73人阅读 评论(0) 收藏
也许你习惯了使用Eclipse编译和打包Android应用.不过,对于使用html5+js开发的phonegap应用,本文建议你抛弃Eclipse,改为使用命令行模式,绝对的快速和方便. 一直以来,E ...
- 哈夫曼树-Fence Repair 分类: 树 POJ 2015-08-05 21:25 2人阅读 评论(0) 收藏
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 32424 Accepted: 10417 Descri ...
- Maya Calendar 分类: POJ 2015-06-11 21:44 12人阅读 评论(0) 收藏
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 70016 Accepted: 21547 D ...
- shell入门之函数应用 分类: 学习笔记 linux ubuntu 2015-07-10 21:48 77人阅读 评论(0) 收藏
最近在学习shell编程,文中若有错误的地方还望各位批评指正. 先来看一个简单的求和函数 #!/bin/bash #a test about function f_sum 7 8 function f ...
随机推荐
- 启用SQL Server 2008的专用管理员连接(DAC)
参考:http://technet.microsoft.com/zh-cn/library/ms178068(v=SQL.105).aspx 问题: 一个在我们公司实习的DBA向我询问如何开启SQL ...
- js中对话框的使用
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- ubuntu搭建ftp服务器
(1).首先用命令检查是否安装了vsftpd vsftpd -version 如果未安装用一下命令安装 sudo apt-get install vsftpd 安装完成后,再次输入vsftpd -v ...
- Codeforces Beta Round #9 (Div. 2 Only)
Codeforces Beta Round #9 (Div. 2 Only) http://codeforces.com/contest/9 A gcd水题 #include<bits/stdc ...
- PHP资源列表(转)
一个PHP资源列表,内容包括:库.框架.模板.安全.代码分析.日志.第三方库.配置工具.Web 工具.书籍.电子书.经典博文等等. 初始翻译信息来自:<推荐!国外程序员整理的 PHP 资源大全& ...
- php的静态化
原理,将动态的页面,存储为静态的HTML静态页,使浏览器直接请求该静态页. 测试:一个PHP动态页面与一个静态页面所消耗的时间 一般可以使用apache自带的ab(apache bench)程序来测试 ...
- Linux wget命令
一.简介 wget是一个Linux系统中的下载文件的工具,它用在命令行下.对于Linux用户是必不可少的工具,我们经常要下载一些软件或从远程服务器恢复备份到本地服务器.wget支持HTTP,HTTPS ...
- Luogu 2912 [USACO08OCT]牧场散步Pasture Walking
快乐树剖 #include<cstdio> #include<cstring> #include<algorithm> #define rd read() #def ...
- BZOJ1222 [HNOI2001]产品加工 - 动态规划- 背包
题解 怎么看都不像是个背包,直到我看了题解→_→, 第一次碰到这么奇怪的背包= = 定一个滚动数组$F_i$, $i$表示机器$a$用了$i$的时间, $F_i$表示机器$b$用了$F_i$的时间, ...
- Laravel 日期时间处理包 Carbon 的应用
在编写 PHP 应用时经常需要处理日期和时间,这篇文章带你了解一下 Carbon – 继承自 PHP DateTime 类的 API 扩展,它使得处理日期和时间更加简单.Laravel 中默认使用的时 ...