zoukankan      html  css  js  c++  java
  • 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 |Ai,j| < 104.

    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 }
  • 相关阅读:
    Winform中怎样设置ContextMenuStrip右键菜单的选项ToolStripMenuItem添加照片
    JavaScript垃圾回收机制
    前端如何处理内存泄漏
    前端缓存
    深入理解vue-router之keep-alive
    (淘宝无限适配)手机端rem布局详解
    mysql不会使用索引,导致全表扫描情况
    MYSQL性能优化的最佳20+条经验
    深拷贝与浅拷贝的区别,实现深拷贝的几种方法
    vue组件通信方式总结
  • 原文地址:https://www.cnblogs.com/CKboss/p/3014163.html
Copyright © 2011-2022 走看看