POJ 2078 Martrix

                                                             Matrix
Time Limit: 2000MS Memory Limit: 30000K
Total Submissions: 3096 Accepted: 1612

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 |A i,j| < 10 4.

Output

For each test case, print a line containing the minimum value of the maximum of column sums.

Sample Input

24 63 731 2 34 5 67 8 9-1

 

 

 1 #include <iostream>
 2 #include <algorithm>
 3 
 4 using namespace std;
 5 
 6 int n;
 7 int mini=9999999;
 8 
 9 void zhuan(int cur,int a[8][8])
10 {
11     reverse(a[cur],a[cur]+n-1);
12     reverse(a[cur],a[cur]+n);
13 }
14 
15 void dfs(int cur,int a[8][8])
16 {
17     if(cur!=n)
18     {
19         for(int i=0;i<n;i++)
20         {
21             zhuan(cur,a);
22             dfs(cur+1,a);
23         }
24     }
25     else if(cur==n)
26     {
27         int sum;
28         int maxx=-1;
29         for(int i=0;i<n;i++)
30         {
31             sum=0;
32             for(int j=0;j<n;j++)
33             {
34                 sum+=a[j][i];
35             }
36             if(sum>maxx)
37                 maxx=sum;
38         }
39         if(maxx<mini)
40             mini=maxx;
41     }
42 }
43 
44 int main()
45 {
46     int a[8][8];
47     cin>>n;
48     while(n!=-1)
49     {
50 
51         for(int i=0;i<n;i++)
52         {
53             for(int j=0;j<n;j++)
54             {
55                 cin>>a[i][j];
56             }
57         }
58         mini=9999999;
59         dfs(0,a);
60 
61         cout<<mini<<endl;
62 
63     cin>>n;
64     }
65 
66     return 0;
67 }

 

转载于:https://www.cnblogs.com/CKboss/archive/2013/04/11/3014163.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值