3 solutions
-
1
dp解法:
如果(i,j)为1,那么只有在(i-1,j),(i,j-1),(i-1,j-1)都为1时,边长才能+1
所以可以得到:f[i][j]=min{(i-1,j),(i,j-1),(i-1,j-1)}
for example:
已知:
2 3
9 ?
那么“?”的值就是2+1=3
代码如下:
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> int n, m; int a[105][105], f[105][105]; int ans = 0; int main() { std::cin >> n >> m; for(int i = 0; i < 100; i ++) { for(int j = 0; j < 100; j ++) { f[i][j] = 0; } }//初始化 for(int i = 1;i <= n; i ++) { for(int j = 1;j <= m;j ++) { scanf("%d", &a[i][j]); if(a[i][j] == 1) { f[i][j] = std::min(std::min(f[i - 1][j], f[i][j - 1]), f[i - 1][j - 1]) + 1;//状态转移公式 } ans = std::max(ans, f[i][j]); } } std::cout << ans; return 0; }
-
0
#include <bits/stdc++.h> using namespace std; bool check(bool map[101][101],short x1,short y1,short x2,short y2){ for (short i=x1;i<=x2;i++){ for (short i1=y1;i1<=y2;i1++){ if (map[i][i1]==0){ return 0; } } } return 1; } bool find(short a,bool map[101][101],short n,short m){ for (short i=0;i<=n-a;i++){ for (short i1=0;i1<=m-a;i1++){ if (check(map,i,i1,i+a-1,i1+a-1)==1){ return 1; } } } return 0; } int main(){ short n,m; bool map[101][101]; cin >> n >> m; for (short i=0;i<n;i++){ for (short i1=0;i1<m;i1++){ cin >> map[i][i1]; } } for (short i=max(n,m);i>1;i--){ if (find(i,map,n,m)==1){ cout << i; return 0; } } cout << 1; return 0; }
-
-1
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> int n, m; int a[105][105], f[105][105]; int ans = 0; int main() { std::cin >> n >> m; for(int i = 0; i < 100; i ++) { for(int j = 0; j < 100; j ++) { f[i][j] = 0; } }//初始化 for(int i = 1;i <= n; i ++) { for(int j = 1;j <= m;j ++) { scanf("%d", &a[i][j]); if(a[i][j] == 1) { f[i][j] = std::min(std::min(f[i - 1][j], f[i][j - 1]), f[i - 1][j - 1]) + 1;//状态转移公式 } ans = std::max(ans, f[i][j]); } } std::cout << ans; return 0; }
- 1
Information
- ID
- 383
- Time
- 1000ms
- Memory
- 125MiB
- Difficulty
- 2
- Tags
- # Submissions
- 8
- Accepted
- 6
- Uploaded By