代码
作者:
羽_qi
,
2022-03-30 22:00:34
,
所有人可见
,
阅读 199
#include <iostream>
#include <cstring>
#include <algorithm>
#include<stdio.h>
using namespace std;
const int N=1010;
int li[N][N],ri[N][N];
int ai[N];
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
for(int i=1;i<=n;i++)
{
cin>>ai[i];
}
for(int len=1;len<=n;len++)
{
for(int i=1;i+len-1<=n;i++)
{
int j=i+len-1;
if(len==1)
{
li[i][i]=ri[i][i]=ai[i];
continue;
}
int L=li[i][j-1];
int R=ri[i][j-1];
int x=ai[j];
if(x==R)li[i][j]=0;
else if((x<L&&x<R)||(x>L&&x>R))li[i][j]=x;
else if(L>R)li[i][j]=x-1;
else li[i][j]=x+1;
L=li[i+1][j],R=ri[i+1][j];
x=ai[i];
if(x==L)ri[i][j]=0;
else if((x>L&&x>R)||(x<L&&x<R))ri[i][j]=x;
else if(L<R)ri[i][j]=x-1;
else ri[i][j]=x+1;
}
}
if(li[2][n]==ai[1]) cout << "0"<<endl;
else cout << "1"<<endl;
}
return 0;
}