Vijos P1063 迎春舞会之交谊舞 DP

时间:2021-02-08 12:06:18

题目链接:https://vijos.org/p/1063

题意:有n(n <= 100)行,每行有2*i-1个可显字符'#'与'-',组成一个倒三角形,问由'-'组成的最大三角形的'-'的个数为多少?

思路:顶点为倒三角,即行列奇偶相同;对于一个顶点可以扩展的最大边长首先需要上面三角为'-',这样只需建立在顶点上一行的左右两个点的最大边长即可;

三角形个数就是边长的平方;

ps:开始我想的是从列的角度看轴线的左右两边的min,然后模拟行。真是醉了。

#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 namespace std;
#define rep0(i,l,r) for(int i = (l);i < (r);i++)
#define rep1(i,l,r) for(int i = (l);i <= (r);i++)
#define rep_0(i,r,l) for(int i = (r);i > (l);i--)
#define rep_1(i,r,l) for(int i = (r);i >= (l);i--)
#define MS0(a) memset(a,0,sizeof(a))
#define MS1(a) memset(a,-1,sizeof(a))
#define MSi(a) memset(a,0x3f,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m+1, r, rt << 1|1
typedef pair<int,int> PII;
#define A first
#define B second
#define MK make_pair
typedef __int64 ll;
template<typename T>
void read1(T &m)
{
T x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
m = x*f;
}
template<typename T>
void read2(T &a,T &b){read1(a);read1(b);}
template<typename T>
void read3(T &a,T &b,T &c){read1(a);read1(b);read1(c);}
template<typename T>
void out(T a)
{
if(a>) out(a/);
putchar(a%+'');
}
char c[][];
int d[][];
int main()
{
int n;
read1(n);
rep1(i,,n)
gets(c[i]+);
int len = *n,ans = ;
rep0(i,,len){
if(c[][i] == '-'){ d[][i] = ;ans = ;}
}
rep1(i,,n){
rep1(j,i,len-i)
if(c[i][j] == '-'){
d[i][j] = ;
if((i&) == (j&) && c[i-][j] == '-' && c[i-][j-] == '-' && c[i-][j+] == '-')
d[i][j] = min(d[i-][j+]+,d[i-][j-]+);
ans = max(ans,d[i][j]);
}
}
printf("%d\n",ans*ans);
return ;
}