Bzoj 1567 [Jsoi2008]blue Mary's battle map

Source: Internet
Author: User

The time limit of 10 seconds, suddenly stunned, think of a n^5 solution, decisive to write.

Use F[I1][J1][I2][J2] to indicate how much of the same line starts from the (i1,j1) and B matrices (i2,j2) of the A matrix.

Then enumerate the i1,i2,j1,j2 and then judge a few lines.

1#include <iostream>2#include <cstdio>3 using namespacestd;4 intN;5 intans=0;6 Long Longa[ -][ -],b[ -][ -];7 intf[ -][ -][ -][ -];8 intMain ()9 {Tenscanf"%d",&n); One      for(intI=1; i<=n;i++) A     { -          for(intj=1; j<=n;j++) -scanf"%lld",&a[i][j]); the     } -      for(intI=1; i<=n;i++) -     { -          for(intj=1; j<=n;j++) +scanf"%lld",&b[i][j]); -     } +      for(inti1=1; i1<=n;i1++) A     { at          for(intj1=1; j1<=n;j1++) -         { -              for(intI2=1; i2<=n;i2++) -             { -                  for(intJ2=1; j2<=n;j2++) -                 { in                     intt=0; -                      while(t+j1<=n && t+j2<=n && a[i1][j1+t]==b[i2][j2+t]) t++; to                     if(t<0) t=0; +f[i1][j1][i2][j2]=T; -                 } the             } *         } $     }Panax Notoginseng      for(inti1=1; i1<=n;i1++) -     { the          for(intj1=1; j1<=n;j1++) +         { A              for(intI2=1; i2<=n;i2++) the             { +                  for(intJ2=1; j2<=n;j2++) -                 { $                     intnow=F[i1][j1][i2][j2]; $                     if(now==0)Continue; -                     intt=1; -                     if(ans==0) ans=1; the                      while(now && t+i1<=n && t+i2<=N) -                     {Wuyi                         if(F[i1+t][j1][i2+t][j2]<now) now=f[i1+t][j1][i2+T] [J2]; theAns=max (Ans,min (t+1, now)); -t++; Wu                     } -                 } About             } $         } -     } -printf"%d\n", ans); -     return 0; A } +             
View Code

Bzoj 1567 [Jsoi2008]blue Mary's battle map

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.