POJ 2029 Get Many Persimmon Trees [dp]
来源:互联网 发布:矩阵分析 答案pdf 编辑:程序博客网 时间:2024/05/09 04:15
题意:
给一个矩阵,里面分布着n个星号。
给定一个小矩阵,问最大可以圈进多少个星号。
思路:
dp方程:
dp1[i][j]=dp1[i-1][j]+dp1[i][j-1]-dp1[i-1][j-1]+a[i][j];//代表从(1,1)到(j,i)圈进的星数。
dp2[i][j]=dp1[i][j]-dp1[i-ty][j]-dp1[i][j-tx]+dp1[i-ty][j-tx];//代表以(j,i)为右下角的小矩阵圈进的星数。
没什么陷阱,1A.
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a)<(b)?(a):(b))using namespace std;const int N=105;const int inf=(1<<30);int n,m;int ty,tx;int a[N][N];int dp1[N][N];int dp2[N][N];void solve(){int ans=0;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){dp1[i][j]=dp1[i-1][j]+dp1[i][j-1]-dp1[i-1][j-1]+a[i][j];dp2[i][j]=dp1[i][j]-dp1[i-ty][j]-dp1[i][j-tx]+dp1[i-ty][j-tx];ans=Max(ans,dp2[i][j]);}}printf("%d\n",ans);}int main(){int num;while(scanf("%d",&num),num){memset(a,0,sizeof(a));memset(dp1,0,sizeof(dp1));memset(dp2,0,sizeof(dp2));scanf("%d%d",&m,&n);int x,y;for(int i=1;i<=num;i++){scanf("%d%d",&x,&y);a[y][x]=1;}scanf("%d%d",&tx,&ty);solve();}return 0;}
- POJ 2029 Get Many Persimmon Trees [dp]
- POJ 2029--Get Many Persimmon Trees +DP
- poj- 2029 -Get Many Persimmon Trees (DP)
- poj 2029 Get Many Persimmon Trees (DP)3Ways
- 【POJ 2029】 Get Many Persimmon Trees(DP)
- 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
- POJ 2029 Get Many Persimmon Trees
- poj 2029 Get Many Persimmon Trees
- POJ 2029 Get Many Persimmon Trees
- RedHat 启动时出现“正在决定eth0的信息失败”解决方法
- C#一些经常忘的小东西
- 用 eclipse 配置 web service的注意事项
- 从"搞笑"到"诺贝尔奖"
- jQuery的核心函数
- POJ 2029 Get Many Persimmon Trees [dp]
- 傅里叶变换
- 火车套利
- 定时备份数据库SQL
- cms:一个行业的沦陷
- Asp.net 中配置 CKEditor和CKFinder
- 解决Navicat 报错:1130-host ... is not allowed to connect to this MySql server,MySQL不允许从远程访问的方法 .
- 年薪40万的一道面试题
- APK 变成 ZIP:Android 手机应用程序文件下载服务器需要注意的问题