#include<iostream>
#include<cstdio>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>
#include<deque>
#include<iterator>
#include<assert.h>
#include<bitset>
#include<climits>
#include<ctime>
#include<complex>
using namespace std;
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define LL long long
#define S(a) scanf("%d",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define KS printf("Case %d: ",kk++)
#define MOD 1000000007
#define MX 100010
int row[110][110],mat[110][110],n,m;
int func(int start, int end)
{
int i,j,curnt=0, mx=-1270000;
for(i=1;i<=n;i++)
{
j=row[i][end]-row[i][start-1];
curnt+=j;
if(curnt>mx) mx=curnt;
if(curnt<0) curnt=0;
}
return mx;
}
int main()
{
int i,j,temp,tc,x1,x2,y1,y2;
cin>>tc;
while(tc--)
{
cin>>n;
for(i=0;i<=n;i++)
row[i][0]=0;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
mat[i][j]=1;
cin>>m;
while(m--)
{
cin>>x1>>y1>>x2>>y2;
for(i=x1;i<=x2;i++)
for(j=y1;j<=y2;j++)
mat[i][j]=-1e5;
}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
//cin>>mat[i][j];
row[i][j]=row[i][j-1]+mat[i][j];
}
temp=0;
for(i=1;i<=n;i++)
for(j=i;j<=n;j++)
temp=max(temp,func(i,j));
cout<<temp<<endl;
}
return 0;
}
No comments:
Post a Comment