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 ...
随机推荐
- Linux网络通信
使用TCP协议的socket 1.网络字节序 由于在主机存储为小端序,网络传输为大端序,并且在网络中需要读取IP号和端口号,所以发送端要将小端序转为大端序,接收端将大端序转为小端序 #include ...
- hadoop无法启动常见原因
1.Could not chdir to home directory /home/USER: Permission denied 启动datanode时会报这个错误,尝试利用ssh登录datanod ...
- BIGDECIMAL 四舍五入等取舍问题
我输入的是1.35,但是电脑不可能取到整数,他的值如下:初始化数据:1.350000000000000088817841970012523233890533447265625ROUND_DOWN); ...
- conductor APIs
任务和工作流元数据 端点 描述 输入 GET /metadata/taskdefs 获取所有任务定义 N / A GET /metadata/taskdefs/{taskType} 检索任务定义 任务 ...
- win10关闭后台应用程序进程的方法
一)win10系统后台应用有两大特点: 1.win10系统有许多系统自带应用软件,在系统任务栏中看不到任何自带的应用程序运行 2.但通过任务管理器的进程中,可直观的看到许多非系统进程正在运行. 二)后 ...
- 获取Activity中得到焦点的EditText
Android Activity中获取当前焦点的控件,自动化输入EditText 获取焦点的view对象 View view=getWindow().getDecorView().findFocus( ...
- EasyUI多选的获取
function deletePRE() { var rows = $('#dg').datagrid('getSelections'); var ids = []; var other_ids = ...
- 通过Chrome的inspect对手机webview进行调试
使用chrome的inspect可以对手机上的webview进行调试,因为真机没有什么比较好的调试工具,而chrome提供了这一个工具可以比较方便的查看真机上的元素,以及进行调试. 其实我对webvi ...
- V4 V7 V13支持包的区别
三者均为支持包,可以让低版本系统使用高版本特性,支持最小版本有差异 V4支持1.6以上 V7支持2.1以上 V13支持3.2以上 V7依赖V4
- Asp.net中判断是否是指定页面请求的代码示例
//获取请求网址,非法请求,返回主页 if (Request.UrlReferrer != null) { string requstUrl = Request.UrlReferrer.Absolut ...