本文主要是介绍POJ 2029 DP || 暴力,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在大矩形中找一个小矩形
使小矩形包含的*最多
暴力或者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 || 暴力的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!