USACO3.34Home on the Range(DP)
2013-08-21 13:46
477 查看
之前做过一道类似的 国际象棋盘神马的。。
统计出以每个1作为右下角的最大正方形 那么以大于二到这个最大值之间为边的正方形都可以以这个为右下角 累加就可以了
dp[i][j] = min(dp[i-1][j],dp[i-1][j-1],dp[i][j-1])+1;
View Code
统计出以每个1作为右下角的最大正方形 那么以大于二到这个最大值之间为边的正方形都可以以这个为右下角 累加就可以了
dp[i][j] = min(dp[i-1][j],dp[i-1][j-1],dp[i][j-1])+1;
/* ID: shangca2 LANG: C++ TASK: range */ #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> using namespace std; int dp[255][255],num[255]; char s[255][255]; int main() { freopen("range.in","r",stdin); freopen("range.out","w",stdout); int i,j,n; cin>>n; for(i = 1; i <= n ;i++) for(j = 1; j <= n ; j++) { cin>>s[i][j]; if(s[i][j]=='1') dp[i][j] =1; } for(i = 2; i <= n ; i++) { for(j = 2 ; j <= n ; j++) { if(s[i][j]=='1'&&s[i-1][j]=='1'&&s[i-1][j-1]=='1'&&s[i][j-1]=='1') dp[i][j] = min(min(dp[i-1][j],dp[i-1][j-1]),dp[i][j-1])+1; } } for(i = 2; i <= n ; i++) for(j = 2; j <= n ;j++) { for(int g = 2 ; g <= dp[i][j] ; g++) num[g]++; } for(i = 2; i <= n ; i++) if(num[i]) cout<<i<<" "<<num[i]<<endl; return 0; }
View Code
相关文章推荐
- Home on the Range USACO 3.3 (dp阵亡)
- USACO Section 3.3 Home on the Range(dp)
- USACO / Home on the Range (DP统计正方形个数)
- usaco Home on the Range java ---DP
- Home On The Range_usaco3.3_dp
- USACO-Section 3.3 Home on the Range (树状数组||DP)
- USACO--3.3Home on the Range+DP
- USACO Home on the Range
- USACO Section 3.3 Home on the Range - 优化的BFS..
- USACO home on the range C 语言实现
- USACO 3.3 Home on the Range (range)
- USACO Home on the Range 解题报告
- USACO Home on the Range
- USACO3.3.4 Home on the Range (range)
- usaco Home on the Range
- usaco Home on the Range
- USACO3.3.4 Home on the Range (range)
- [USACO3.3]家的范围 Home on the Range
- USACO Section 3.3 Home on the Range
- USACO 3.3 Home on the Range