Qz’s Maximum All One Square+csuoj+dp
来源:互联网 发布:阿里云备案订单在哪里 编辑:程序博客网 时间:2024/05/22 04:49
1424:
Qz’s Maximum All One Square
Time Limit: 5 Sec Memory Limit: 128 MB1424:
Qz’s Maximum All One Square
Submit: 145 Solved: 43
[Submit][Status][Web Board]
Description
YH gave Qz an odd matrix consists of one or zero. He asked Qz to find a square that has the largest area. The problem is not so easy, that means the square you find must not contain any zero. Your task is finding the square and you only need to output the area of the matrix. If you help Qz, he will thanks you a lot and treat you a meal. Please call him after the contest if you solve this problem. His number is XXXXXXXXXXXX. Hehe~
Input
For each case, Qz first give you 2 number n and m (1 <= n <= 1000, 1 <= m <= 1000),the matrix is in size of n columns and m rows.
Then Qz will give you the matrix. To avoid cost his money, Qz decided to make this problem a little difficult... Do not worry, he just gave you multiple cases.
Output
For each test case, output the desired answer.
Sample Input
2 21 11 14 41 1 0 01 1 1 11 1 1 01 1 0 1
Sample Output
44
解决方案:dp题,公式为dp[i][j]=min(dp[i][j-1],dp[i-1][j],dp[i-1][j-1])+1;
code:#include<iostream>#include<cstdio>using namespace std;int dp[1003][1003];int Mat[1003][1003];int main(){ int n,m; while(~scanf("%d%d",&n,&m)){ int temp=n;n=m;m=temp; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ scanf("%d",&Mat[i][j]); } } int ans=0; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(Mat[i][j]){ dp[i][j]=min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1]))+1; if(dp[i][j]>ans) ans=dp[i][j]; } else dp[i][j]=0; } } printf("%d\n",ans*ans); } return 0;}
1424:
0 0
- Qz’s Maximum All One Square+csuoj+dp
- Problem H: Qz’s Maximum All One Square
- CSU 1424 Qz’s Maximum All One Square
- CSU 1424 Qz’s Maximum All One Square
- csu1424_Qz’s Maximum All One Square
- Maximum size square sub-matrix with all 1s
- Geeks 面试题: Maximum size square sub-matrix with all 1s
- Random Integers+csuoj+dp
- Stock Wave+csuoj+简单dp
- E - Maximum Square
- CSUOJ
- CSUOJ
- One for all, all for one
- POJ3494Largest Submatrix of All 1’s(DP)
- poj3494 Largest Submatrix of All 1’s 单调栈+dp
- CSUOJ 1729 齿轮传动(基础DP)
- CSUOJ 1592 石子归并(区间DP)
- maximum.s
- 历史上最有影响力的10款开源项目
- Java线程的互斥
- 找出数组中唯一的重复元素
- magento给支付页面和会员页面增加https
- hdu-2206-Ip的计算
- Qz’s Maximum All One Square+csuoj+dp
- Linux常用命令
- (C#)Windows Shell 外壳编程系列2 - 解释,从“桌面”开始展开
- PAT 1001 1002
- jhsgfdkshglshlg
- (C#)Windows Shell 外壳编程系列3 - 上下文菜单(iContextMenu)(一)右键菜单
- app启动流程基于4.4.3源码
- Java中创建线程的两种方式
- (C#)Windows Shell 外壳编程系列4 - 上下文菜单(iContextMenu)(二)嵌入菜单和执行命令