king's trouble II
来源:互联网 发布:windows清理助手3.0 编辑:程序博客网 时间:2024/05/22 17:53
Description
Long time ago, a king occupied a vast territory.
Now there is a problem that he worried that he want to choose a largest square of his territory to build a palace.
Can you help him?
For simplicity, we use a matrix to represent the territory as follows:
0 0 0 0 0
0 1 0 1 0
1 1 1 1 0
0 1 1 0 0
0 0 1 0 0
Every single number in the matrix represents a piece of land, which is a 1*1 square
1 represents that this land has been occupied
0 represents not
Obviously the side-length of the largest square is 2
Input
The first line of the input contains a single integer t (1≤t≤5) — the number of cases.
For each case
The first line has two integers N and M representing the length and width of the matrix
Then M lines follows to describe the matrix
1≤N,M≤1000
Output
For each case output the the side-length of the largest square
Sample Input
2
5 5
0 0 0 0 0
0 1 0 1 0
1 1 0 1 0
0 1 1 0 0
0 0 1 0 0
5 5
0 0 0 0 0
0 1 0 1 0
1 1 1 1 0
0 1 1 0 0
0 0 1 0 0
Sample Output
1
2
dp
#include<stdio.h>#include<iostream>#include<string.h>using namespace std;int a[1010][1010];int dp[1010][1010];int main(){ int t; scanf("%d",&t); while(t--) { int n,m; scanf("%d%d",&n,&m); memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { scanf("%d",&a[i][j]); } } int ans=0; for(int i=1;i<n;i++) { for(int j=1;j<m;j++) { if(a[i][j]==1) { dp[i][j]=min(dp[i][j-1],min(dp[i-1][j-1],dp[i-1][j]))+1; } ans=max(ans,dp[i][j]); } } printf("%d\n",ans); }}
0 0
- king's trouble II
- king's trouble II
- king's trouble II SCU
- SCU4488 king's trouble II(DP)
- king's trouble II (单调栈)
- 四川省赛-E king's trouble II
- king's trouble I
- king's trouble I
- SCU 4488 king's trouble II(dp||枚举)
- SCU~4488: king's trouble II(dp)
- SCU4487 king's trouble I(深搜DFS)
- SCU 4487 king's trouble I
- ZJU2058The Archaeologist's Trouble II
- ZOJ 2058 The Archaeologist's Trouble II
- ZJU2058 The Archaeologist's Trouble II - 贪心+构造
- SCU 4487 king's trouble I(dfs)||(0找1)
- hdu 2832 Snail’s trouble
- King's Man
- 程序员编程生涯中会犯的7个错误
- Hadoop安装
- 文章标题
- pta 集合相似度 (stl)
- 一次面试经历
- king's trouble II
- LeetCode 98. Validate Binary Search Tree
- Tomcat各版本说明
- Java从入门到精通阅读笔记(第4版)13
- 公众平台测试帐号开发全流程第8篇-素材管理
- Linux 目录结构及文件基本操作
- 读书笔记8 《所谓情商高,就是会说话》 佐佐木圭一
- Android应用程序打包时,出现错误:"XXX" is not translated in..
- C++使用opencv实现彩色直方图计算