标签:io for amp size poj dp return print
使小矩形包含的*最多
暴力或者DP 水题
暴力:
#include "stdio.h" #include "string.h" int main() { int n,m,w,i,s,t,j,k,l,ans,sum,x,y; int map[101][101]; while (scanf("%d",&w)!=EOF) { if(w==0) break; scanf("%d%d",&n,&m); memset(map,0,sizeof(map)); while (w--) { scanf("%d%d",&x,&y); map[x][y]=1; } scanf("%d%d",&s,&t); ans=0; for (i=1;i<=n-s+1;i++) for (j=1;j<=m-t+1;j++) { sum=0; for (l=0;l<s;l++) for (k=0;k<t;k++) sum+=map[i+l][j+k]; if (sum>ans) ans=sum; } printf("%d\n",ans); } return 0; }
#include "stdio.h" #include "string.h" int Max(int a,int b) { if (a<b) return b; else return a; } int main() { int n,m,w,i,s,t,j,ans,x,y; int sum[101][101],map[101][101]; while (scanf("%d",&w)!=EOF) { if(w==0) break; scanf("%d%d",&n,&m); memset(map,0,sizeof(map)); while (w--) { scanf("%d%d",&x,&y); map[x][y]=1; } scanf("%d%d",&s,&t); memset(sum,0,sizeof(sum)); for (i=1;i<=n;i++) for (j=1;j<=m;j++) sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+map[i][j]; ans=0; for (i=s;i<=n;i++) for (j=t;j<=m;j++) { ans=Max(ans,sum[i][j]-sum[i-s][j]-sum[i][j-t]+sum[i-s][j-t]); } printf("%d\n",ans); } return 0; }
POJ 2029 DP || 暴力,布布扣,bubuko.com
标签:io for amp size poj dp return print
原文地址:http://blog.csdn.net/u011932355/article/details/38300617