Bzoj 3128 Usaco2013 Open Figure Eight

Source: Internet
Author: User

Topic: Given a matrix with a bad point, the largest "8" glyphs can be drawn.

The "8" glyph satisfies:

* The number 8 consists of the upper and lower two rectangles.
* The upper and lower two rectangles of the number 8 satisfy at least one cell inside the rectangle.
* The bottom edge of the top rectangle of the number 8 must be a subset of the top edge of the rectangle.
* The number 8 can only be engraved in the perfect marble part.
* The number 8 is specified as the product of the area of the upper rectangle and the lower rectangle, and they want to achieve maximum score.

Enumerates the bottom edge of the top rectangle, which can be transferred with the bottom edge O (1) of the previous line, and then each row O (n^2) expands to the left and right

The top edge of the bottom rectangle is then enumerated and can be transferred with the top O (1) of the next line, and the maximum area of the top rectangle has been calculated, and O (1) Updates the answer

Final time complexity O (n^3) Beware of memory

I lost 10 points on the test without a solution. It's so ...

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 302using Namespace Std;int n;long long Ans=-1;char map[m][m];int sum[m][m];int f[m][m][m],g[m][m][m];int Get_Sum (int x1,int y1, int X2,int y2) {return sum[x2][y2]+sum[x1-1][y1-1]-sum[x2][y1-1]-sum[x1-1][y2];} int main () {freopen ("eight.in", "R", stdin), Freopen ("Eight.out", "w", stdout); int i,j,k;cin>>n;for (i=1;i<=n; i++) scanf ("%s", map[i]+1); for (i=1;i<=n;i++) for (j=1;j<=n;j++) sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][ j-1]+ (map[i][j]== ' * '); for (i=1;i<=n-2;i++) for (j=i+2;j<=n;j++) {int last=0;for (k=1;k<=n;k++) {if (Map[k][i] =='*'|| map[k][j]== ' * ') last=0;if (! Get_sum (k,i,k,j)) {if (last) f[k][i][j]= (k-last-1) * (j-i-1); elselast=k;}} Last=0;for (k=n;k;k--) {if (map[k][i]== ' * ' | | map[k][j]== ' * ') last=0;if (! Get_sum (k,i,k,j)) {if (last) g[k][i][j]= (last-k-1) * (j-i-1); elselast=k;}} for (i=1;i<=n;i++) {to (j=1;j<=n-3;j++) for (k=j+3;k<=n;k++) {if (Get_sum (i,j,i,k)) Break;f[i][j][k]=max (f[i ][j][k],f[i][j][k-1]);} for (j=n;j>=4;j--) for (k=j-3;k;k--) {if (Get_sum (i,k,i,j)) Break;f[i][k][j]=max (F[i][k][j],f[i][k+1][j]);}} for (i=3;i<=n-2;i++) for (j=1;j<=n-2;j++) for (k=j+2;k<=n;k++) if (! Get_sum (i,j,i,k)) Ans=max (ans, (long Long) f[i][j][k]*g[i][j][k]); Cout<<ans<<endl;} あぁ Flower Fire が night Sky Yee Beautiful occupies Misaki いてちょっと cut なく//あぁ wind が time とともに stream weave


Bzoj 3128 Usaco2013 Open Figure Eight

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.