uva 10074 Take the Land
来源:互联网 发布:asp淘宝客源码 编辑:程序博客网 时间:2024/05/22 12:06
原题:
The poor man went to the King and said, “Lord, I cannot maintain my family. Please give me some wealth so that I can survive with my wife and children.” The King replied, “I shall grant you a piece of land so that you can cultivate and grow food for your family. In the southern part of the Kingdom there is a rectangular forest. Trees have been planted there at regular intervals. Some of the trees have been cut for use. You are allowed to take any rectangular piece of land that does not contain any tree.
You need not go to the forest to select the piece of land. I have a map containing 1’s at places where there is a tree and 0s at points where the tree has been cut.”
Help the poor man to find out the largest piece of land. Area of the land is measured in units of number of trees that were there. Your program should take a matrix of 1’s and 0’s as input and output the area of the largest rectangular piece of land that contain no tree. Be careful about the efficiency of your program.
Input
The input file may contain multiple test cases. The first line of each test case contains two integers M and N (1 ≤ M,N ≤ 100) giving the number of rows and columns in the matrix that follows. Each of the next M lines contains N symbols (either ‘0’ or ‘1’). Two consecutive symbols in a line will be separated by a single space. The input terminates with two zeros for M and N.
Output
For each test case in the input print a line giving the area (in terms of the number of trees were there) of the largest rectangular piece of land containing no tree.
Sample Input
6 7
0 1 1 0 1 1 0
0 0 0 0 0 1 0
1 0 0 0 0 0 1
0 1 0 0 0 0 1
1 1 0 0 0 1 0
1 1 0 1 1 0 0
0 0
Sample Output
12
中文
给你一个矩阵,让你算最大0的面积
#include<bits/stdc++.h>using namespace std;int dp[101][101];int sum[101][101];int main(){ ios::sync_with_stdio(false); int t; int row,col; while(cin>>row>>col,row+col) { string s; memset(dp,0,sizeof(dp)); for(int i=1;i<=row;i++) { for(int j=1;j<=col;j++) { int tmp; cin>>tmp; if(tmp) sum[i][j]=0; else sum[i][j]=1; } } for(int i=1;i<row;i++) { for(int j=1;j<=col;j++) { if(sum[i+1][j]==1) { sum[i+1][j]=sum[i][j]+1; } } } int ans=0; for(int i=1;i<=row;i++) { for(int j=1;j<=col;j++) { int width=1; for(int left=j-1;;left--) { if(j==0) break; if(sum[i][left]<sum[i][j]) break; else width++; } for(int right=j+1;;right++) { if(right==col+1) break; if(sum[i][right]<sum[i][j]) break; else width++; } dp[i][j]=sum[i][j]*width; ans=max(dp[i][j],ans); } } cout<<ans<<endl; } return 0;}
思路
和uva 836一个问题,只不过这道题输入方式比较人性化
算是买一赠一的问题 哈哈
- UVa 10074 - Take the Land
- UVa:10074 Take the Land
- UVa 10074 - Take the Land
- uva 10074 Take the Land
- uva 10074 Take the Land
- UVA 10074 Take the Land(最大子矩阵和变形)
- Take the Land - UVa 10074 变形最大子矩阵和
- UVA 10074 Take the Land dp/暴力+剪枝
- UVa 10074 Take the Land (转化思想&最大子矩阵和)
- uva 10499 - The Land of Justice
- uva-10499 - The Land of Justice
- UVa 10499 - The Land of Justice
- UVa 10499 - The Land of Justice
- UVA 10499 The Land of Justice
- uva 10499 - The Land of Justice
- uva 10499 The Land of Justice
- UVA 10499 The Land of Justice
- UVa 10499 - The Land of Justice
- python cmath的用法
- Java并发
- 互斥锁和条件变量的结合使用
- VUE快速入门心得——render函数
- 多线程共享资源
- uva 10074 Take the Land
- 洛谷1006 传纸条
- liunx 优化及性能调优
- mysql
- 剑指offer面试题目:数组中只出现一次的数字
- Android 的事件分发机制
- poj1142 Smith Numbers
- WebView与H5那些事儿(=)
- 内存屏障