USACO3.3.4 Home on the Range (range)
2015-01-30 19:39
369 查看
首先dp,
dp[ i ][ j] 表示以点(i,j)为右下角能取到的最大正方形的边长
点[ i ][ j ]被损坏,dp[i][j]=0, 否则dp[i][j]=min{ dp[ i-1 ][ j ] , dp[ i ][ j - 1] , dp[ i-1 ][ j-1 ] } + 1
扫描dp[ ][ ],记录答案输出即可
dp[ i ][ j] 表示以点(i,j)为右下角能取到的最大正方形的边长
点[ i ][ j ]被损坏,dp[i][j]=0, 否则dp[i][j]=min{ dp[ i-1 ][ j ] , dp[ i ][ j - 1] , dp[ i-1 ][ j-1 ] } + 1
扫描dp[ ][ ],记录答案输出即可
/* ID:xsy97051 LANG:C++ TASK:range */ #include <cstdio> #include <algorithm> #include <iostream> using namespace std; bool a[255][255]; int dp[255][255],cnt[255]; int main() { freopen("range.in","r",stdin); freopen("range.out","w",stdout); int n; cin>>n; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { char c; cin>>c; if(c=='1') a[i][j]=1; } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(a[i][j]) dp[i][j]=min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1]))+1; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int k=2;k<=dp[i][j];k++) cnt[k]++; for(int i=2;i<=n;i++) if(cnt[i]!=0) cout<<i<<" "<<cnt[i]<<endl; return 0; }
相关文章推荐
- USACO3.3.4--Home on the Range
- USACO3.3.4 Home on the Range (range)
- [USACO3.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
- USACO Section 3.3 Home on the Range(dp)
- USACO Home on the Range
- Home on the Range USACO 3.3 (dp阵亡)
- USACO Section 3.3 Home on the Range - 优化的BFS..
- usaco Home on the Range java ---DP
- USACO-Section3.3 Home on the Range【完全背包】
- USACO-Section 3.3 Home on the Range (树状数组||DP)
- USACO 3.3 Home on the Range
- USACO 3.3 Home on the Range (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