Vijos P1063 Spring Dance Ballroom DP

Source: Internet
Author: User

Title Link:https://vijos.org/p/1063

Test instructions: There are N (n <= 100) rows, each line has 2*i-1 characters ' # ' and '-', which make up an inverted triangle, asking what is the number of '-' of the largest triangle composed of '-'?

Idea: The vertex is inverted triangle, that is, the column is the same; for a vertex can extend the maximum length of the edge of the first need for the upper triangle as '-', so that only a row on the vertex of the left and right two points of the maximum edge length can be;

The number of triangles is the square of the side length;

PS: At first I think of the left and right sides of the axis from the angle of the column, and then simulate the line. It's really drunk.

#include <iostream>#include<cstdio>#include<cstring>#include<string.h>#include<algorithm>#include<vector>#include<cmath>#include<stdlib.h>#include<time.h>#include<stack>#include<Set>#include<map>#include<queue>using namespacestd;#defineRep0 (I,L,R) for (int i = (l); i < (R); i++)#defineREP1 (I,L,R) for (int i = (l); I <= (r); i++)#defineRep_0 (i,r,l) for (int i = (r); i > (l); i--)#defineRep_1 (i,r,l) for (int i = (r); I >= (l); i--)#defineMS0 (a) memset (A,0,sizeof (a))#defineMS1 (a) memset (A,-1,sizeof (a))#defineMSi (a) memset (A,0x3f,sizeof (a))#defineINF 0x3f3f3f3f#defineLson L, M, RT << 1#defineRson m+1, R, RT << 1|1typedef pair<int,int>PII;#defineA First#defineB Second#defineMK Make_pairtypedef __int64 Ll;template<typename t>voidRead1 (T &m) {T x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} M= x*F;} Template<typename t>voidRead2 (T &a,t &b) {Read1 (a); Read1 (b);} Template<typename t>voidRead3 (T &a,t &b,t &c) {Read1 (a); Read1 (b); Read1 (c);} Template<typename t>void  out(T a) {if(a>9) out(ATen); Putchar (A%Ten+'0');}Charc[ the][ About];intd[ the][ -];intMain () {intN;    Read1 (n); REP1 (i,1, N) gets (C[i]+1); intLen =2*n,ans =0; Rep0 (i,1, Len) {        if(c[1][i] = ='-') {d[1][i] =1; ans =1;} } rep1 (I,2, N) {REP1 (J,i,len-i)if(C[i][j] = ='-') {D[i][j]=1; if((i&1) = = (j&1) && c[i-1][J] = ='-'&& c[i-1][j-1]  =='-'&& c[i-1][j+1]  =='-') D[i][j]= Min (d[i-1][j+1]+1, d[i-1][j-1]+1); Ans=Max (ans,d[i][j]); }} printf ("%d\n", ans*ans); return 0;}

Vijos P1063 Spring Dance Ballroom DP

Related Article

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.