标签:include 裸题 font ace == lib dig 思路 +=
题目大意:
有一个01矩阵,求其所有a*b的子矩阵中总和最大的子矩阵的权值和
思路:
二维树状数组
nlogn裸题完事
虽然poj数据太弱了,二维前缀和就过了
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5 #include<cstring> 6 #include<cstdlib> 7 #include<queue> 8 #include<vector> 9 #include<set> 10 #include<stack> 11 #define inf 2147483611 12 #define ll long long 13 #define MAXN 510 14 using namespace std; 15 inline int read() 16 { 17 int x=0,f=1; 18 char ch;ch=getchar(); 19 while(!isdigit(ch)) {if(ch==‘-‘) f=-1;ch=getchar();} 20 while(isdigit(ch)) {x=x*10+ch-‘0‘;ch=getchar();} 21 return x*f; 22 } 23 int c[MAXN][MAXN],x,y,s,t,n,ans; 24 int lowbit(int x) {return x&(-x);} 25 void update(int a,int b) 26 { 27 for(int i=a;i<=y;i+=lowbit(i)) 28 for(int j=b;j<=x;j+=lowbit(j)) 29 { 30 c[i][j]++; 31 } 32 } 33 int sum(int a,int b) 34 { 35 int ans=0; 36 for(int i=a;i>=1;i-=lowbit(i)) 37 for(int j=b;j>=1;j-=lowbit(j)) 38 { 39 ans+=c[i][j]; 40 } 41 return ans; 42 } 43 int main() 44 { 45 int a,b; 46 while(scanf("%d",&n)&&n) 47 { 48 memset(c,0,sizeof(c)); 49 x=read(),y=read(); 50 for(int i=1;i<=n;i++) 51 { 52 a=read(),b=read(); 53 update(b,a); 54 } 55 s=read(),t=read(); 56 ans=-1; 57 for(int i=t;i<=y;i++) 58 for(int j=s;j<=x;j++) 59 { 60 ans=max(ans,sum(i,j)-sum(i-t,j)-sum(i,j-s)+sum(i-t,j-s)); 61 } 62 printf("%d\n",ans); 63 } 64 }
poj 2029 get many persimmon trees
标签:include 裸题 font ace == lib dig 思路 +=
原文地址:http://www.cnblogs.com/yyc-jack-0920/p/7617076.html