BZOJ1218(NOI2003)[激光炸弹]--容斥

【链接】
bzoj1218

【解题报告】

容斥裸题吧。。

#include
#include
using namespace std;
const int maxn=5005;
int n,m,ans,E,K,f[maxn][maxn];
inline char nc()
{
    static char buf[100000],*l,*r;
    if (l==r) r=(l=buf)+fread(buf,1,100000,stdin);
    if (l==r) return EOF; return *l++;
}
inline int Read()
{
    int res=0,f=1; char ch=nc(),cc=ch;
    while (ch<'0'||ch>'9') cc=ch,ch=nc();
    if (cc=='-') f=-1;
    while (ch>='0'&&ch<='9') res=res*10+ch-48,ch=nc();
    return res*f;
}
int main()
{
    freopen("1218.in","r",stdin);
    freopen("1218.out","w",stdout);
    n=m=ans=0; E=Read(); K=Read();
    for (int i=1,x,y; i<=E; i++) x=Read()+1,y=Read()+1,n=max(n,x),m=max(m,y),f[x][y]=Read();
    if (nif (mfor (int i=1; i<=n; i++)
     for (int j=1; j<=m; j++)
      f[i][j]+=f[i-1][j]+f[i][j-1]-f[i-1][j-1];
    for (int i=0; i<=n-K; i++)
     for (int j=0; j<=m-K; j++)
      ans=max(ans,f[i+K][j+K]-f[i][j+K]-f[i+K][j]+f[i][j]);
    printf("%d",ans);
    return 0;
}

你可能感兴趣的:(BZOJ题解,容斥,部分常见刷题网站的题解,By,Greninja,BZOJ题解,By,Greninja)