POJ 2029 Get Many Persimmon Trees
来源:互联网 发布:2009霍华德巅峰数据 编辑:程序博客网 时间:2024/05/20 09:46
这是动态规划?我一点思路怎么也没有。最后还是用矩阵部分求和枚举0MS。
题目大意:
给出一个矩阵,上面有几个点。在给一个小点儿的矩阵,求这个矩阵最多能套上几个点。(注意:小矩阵长宽给定,不能旋转)。
解题思路:
建立数组num[i][j]代表点(1,1)到点(i,j)组成的矩阵里有几个点。
下面是代码:
#include <stdio.h>#include <string.h>int num[105][105];int cal(int x1,int y1,int x2,int y2){ return num[x2][y2]-num[x2][y1]-num[x1][y2]+num[x1][y1];}int max(int a,int b){ if(a<b)a=b; return a;}int main(){ int n,x,y,w,h,c,k; while(scanf("%d",&n),n) { memset(num,0,sizeof(num)); scanf("%d%d",&w,&h); for(int i=0; i<n; i++) { scanf("%d%d",&x,&y); num[x][y]=1; } scanf("%d%d",&c,&k); for(int i=1; i<=w; i++) { int sum=0; for(int j=1; j<=h; j++) { sum+=num[i][j]; if(i!=1) { num[i][j]=num[i-1][j]; } else { num[i][j]=0; //这里开始时收残了~~记住要初始化 ,否则就加两倍了~~ } num[i][j]+=sum; } } int min1=0; for(int i=0;i+c<=w;i++) { for(int j=0;j+k<=h;j++) { min1=max(min1,cal(i,j,i+c,j+k)); } } printf("%d\n",min1); } return 0;}
0 0
- POJ 2029 Get Many Persimmon Trees
- Poj 2029 Get Many Persimmon Trees
- POJ 2029 Get Many Persimmon Trees [dp]
- POJ 2029 Get Many Persimmon Trees (标记)
- POJ 2029 Get Many Persimmon Trees
- poj-2029-Get Many Persimmon Trees-预处理
- POJ 2029 Get Many Persimmon Trees
- poj 2029 Get Many Persimmon Trees
- poj 2029 Get Many Persimmon Trees
- POJ 2029 Get Many Persimmon Trees
- POJ 2029 Get Many Persimmon Trees
- POJ 2029--Get Many Persimmon Trees +DP
- poj 2029 Get Many Persimmon Trees
- POJ 2029 Get Many Persimmon Trees
- poj 2029 Get Many Persimmon Trees
- POJ 2029 Get Many Persimmon Trees
- poj 2029 Get Many Persimmon Trees
- poj- 2029 -Get Many Persimmon Trees (DP)
- 第十四周 阅读
- <编程之美>3.9重建二叉树
- NPU 1205 活动安排
- 微信易信分享接入
- std::string在调试时更改其值
- POJ 2029 Get Many Persimmon Trees
- 斯坦福ML公开课笔记13A——混合高斯模型、混合贝叶斯模型
- x264 - x264_pixel_satd_8x4
- 安全编码实践之五地址空间格局随机化ASLR
- java 获取本地信息大全
- android拉apk程序
- 写在前面的 unity碰撞触发事件
- Google的V8引擎VS2012调用报错
- Java关键字static使用总结