USACO3.3.4 Home on the Range (range)
2014-12-10 09:21
357 查看
dp[i][j]:以点(i,j)为右下角能取到的最大正方形的边长
若arr[i][j]==0,则dp[i][j]=0
否则dp[i][j]=min(dp[i - 1][j], min(dp[i][j - 1], dp[i - 1][j - 1])) + 1
若arr[i][j]==0,则dp[i][j]=0
否则dp[i][j]=min(dp[i - 1][j], min(dp[i][j - 1], dp[i - 1][j - 1])) + 1
/* ID:shijiey1 PROG:range LANG:C++ */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n; int arr[258][258]; int dp[258][258]; int ans[258]; int main() { freopen("range.in", "r", stdin); freopen("range.out", "w", stdout); scanf("%d\n", &n); char c; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { scanf("%c", &c); arr[i][j] = c - '0'; } getchar(); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (!arr[i][j]) dp[i][j] = 0; else dp[i][j] = min(dp[i - 1][j], min(dp[i][j - 1], dp[i - 1][j - 1])) + 1; if (dp[i][j] > 1); ans[dp[i][j]]++; } } for (int i = 2; i <= n; i++) { int re = 0; for (int j = i; j <= n; j++) { re += ans[j]; } if (re) printf("%d %d\n", i, re); } return 0; }
相关文章推荐
- USACO3.3.4 Home on the Range (range)
- USACO3.3.4--Home on the Range
- [USACO3.3.4]Home on the Range
- USACO / Home on the Range (DP统计正方形个数)
- usaco Home on the Range(dp+容斥原理)
- [USACO3.3]家的范围 Home on the Range
- Home On The Range_usaco3.3_dp
- USACO home on the range C 语言实现
- USACO 3.3 Home on the Range(最大子矩阵问题)
- usaco Home on the Range
- USACO3.34Home on the Range(DP)
- usaco 3.3 Home on the Range
- USACO Home on the Range 解题报告
- USACO Home on the Range
- USACO Section 3.3 Home on the Range
- [动态规划]3.3.4 Home on the Range
- USACO-Section 3.3- PROB Home on the Range
- [USACO]Home on the Range
- usaco Home on the Range
- USACO--3.3Home on the Range+DP