zoukankan      html  css  js  c++  java
  • HDU 1559 最大子矩阵

    最大子矩阵

    Time Limit : 30000/10000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 3   Accepted Submission(s) : 1

    Font: Times New Roman | Verdana | Georgia

    Font Size:

    Problem Description

    给你一个m×n的整数矩阵,在上面找一个x×y的子矩阵,使子矩阵中所有元素的和最大。

    Input

    输入数据的第一行为一个正整数T,表示有T组测试数据。每一组测试数据的第一行为四个正整数m,n,x,y(0<m,n<1000 AND 0<x<=m AND 0<y<=n),表示给定的矩形有m行n列。接下来这个矩阵,有m行,每行有n个不大于1000的正整数。

    Output

    对于每组数据,输出一个整数,表示子矩阵的最大和。

    Sample Input

    1
    4 5 2 2
    3 361 649 676 588
    992 762 156 993 169
    662 34 638 89 543
    525 165 254 809 280

    Sample Output

    2474

    Author

    lwg

    Source

    HDU 2006-12 Programming Contest
     
    思路:DP
     
    代码:

    #include <iostream>

    #include <cstdio>

    #include <cstring>

    #include <cstdlib>

    using namespace std;

    int map[1100][1100];

    int temp[1100];

    int t;

    int n,m,x,y;

    int main() {

            scanf("%d",&t);        

    while(t --)        

    {            

    scanf("%d%d%d%d",&n,&m,&x,&y);          

       for(int i = 1;i <= n;i ++)   

                 for(int j = 1;j <= m;j ++)

                      scanf("%d",&map[i][j]);

                int max = 0;

                for(int i = 1;i <= n - x + 1;i ++)

                {                

    memset(temp,0,sizeof(temp));            

         for(int j = 1;j <= m;j ++)

    {        

                  temp[j] = temp[j - 1];       

                 for(int k = i;k < i + x;k ++)   

                       temp[j] += map[k][j];     

                     }             

        for(int k = y;k <= m;k ++){      

                   //printf("%d ",temp[k] - temp[k - y]);    

                     if(temp[k] - temp[k - y] > max)               

             max = temp[k] - temp[k - y];}         

        }       

          printf("%d ",max);   

          }     

        return 0;

    }

  • 相关阅读:
    LNMP安装后MYSQL数据库无法远程访问解决
    Ubuntu忘记root密码怎么办?
    composer安装出现proc_open没有开启问题的解决方案
    LNMP搭建环境遇到的N多坑
    lnmp HTTP ERROR 500
    LNMP集成运行(开发)环境的部署
    最新javamail 使用方案,可以异步发送邮件
    vi常用快捷键
    Dom4j解析XML文件
    Multiple markers at this line @Override的解决方法
  • 原文地址:https://www.cnblogs.com/GODLIKEING/p/3313619.html
Copyright © 2011-2022 走看看