poj 2029 Get Many Persimmon Trees
2011-07-22 16:31
435 查看
#include <iostream> //树状数组 using namespace std; int n,w,h,x,y,s,t,max_val,table[105][105]; int lowbit(int x) { return x&(-x); } void modify(int x,int y) { while(x<100) { int j=y; while(j<100) { table[x][j]++; j+=lowbit(j); } x+=lowbit(x); } } int sum(int x,int y) { int s=0; while(x>0) { int j=y; while(j>0) { s+=table[x][j]; j-=lowbit(j); } x-=lowbit(x); } return s; } int main() { while(scanf("%d",&n)&&n) { scanf("%d%d",&w,&h); memset(table,0,sizeof(table)); while(n--) { scanf("%d%d",&x,&y); modify(x,y); } scanf("%d%d",&s,&t); max_val=0; for(int i=s;i<=w;++i) { for(int j=t;j<=h;++j) { max_val=max(max_val,sum(i,j)-sum(i-s,j)-sum(i,j-t)+sum(i-s,j-t)); //table[0][y]或table[x][0]都始终为0 } } printf("%d\n",max_val); } return 0; } #include <iostream> //dp,与树状数组类似 using namespace std; int n,w,h,x,y,s,t,max_val,dp[105][105],i,j; //dp[x][y]表示从dp[1][1]到dp[x][y]的总和 int main() { while(scanf("%d",&n)&&n) { scanf("%d%d",&w,&h); memset(dp,0,sizeof(dp)); while(n--) { scanf("%d%d",&x,&y); dp[x][y]=1; } for(i=1;i<=w;++i) //i,j不能从2开始,因为这样会忽略掉(1,2)和(2,1)的情况 { for(j=1;j<=h;++j) { dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]; } } scanf("%d%d",&s,&t); max_val=0; for(i=s;i<=w;++i) { for(j=t;j<=h;++j) { max_val=max(max_val,dp[i][j]-dp[i-s][j]-dp[i][j-t]+dp[i-s][j-t]); } } printf("%d\n",max_val); } return 0; }
相关文章推荐
- POJ 2029 Get Many Persimmon Trees(二维BIT)
- 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 && zoj 1716 Get Many Persimmon Trees
- POJ 2029 && ZOJ 1716 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 && ZOJ 1716 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 暴力枚举