http://acm.pku.edu.cn/JudgeOnline/problem?id=1068
鍒嗘瀽錛?br>
(1) The first element of W-sequence must be 1.
(2) The matched left parenthesis is the closest unmatched left parenthesis.
(3) The left must have left parenthesis and the first right parenthiesis matches with the left parenthesis nearest to it.
(4) If , ,else w[i]=i+1; the subscript must be from 0.
鏀惰幏錛氬眬閮ㄥ彉閲忓拰鍏ㄥ眬鍙橀噺璋ㄦ厧浣跨敤銆傝繖涓唬鐮佸湪鐢ㄥ叏灞鍙橀噺bool flag鏃跺湪澶栭儴榪涜鍒濆鍖栵紝鍦ㄥ驚鐜綋鍐呴儴鏈垵濮嬪寲錛屽鑷村墠闈㈢殑寰幆褰卞搷鍚庨潰鐨勭粨鏋滆屽嚭閿欍傚洜姝ゅ鍏ㄥ眬鍙橀噺鍦ㄤ綍澶勮繘琛屽垵濮嬪寲蹇呴』鍗佸垎緇嗗績銆?br>浠g爜錛?br>
#include"iostream"
#include"stdio.h"
using namespace std;

int p[21],w[21],t,n,k;
bool flag;

int main()


{
scanf("%d",&t);
for(int i=0;i<t;i++)

{
scanf("%d",&n);
for(int j=0;j<n;j++)
scanf("%d",&p[j]);
w[0]=1;
for(int j=1;j<n;j++)

{
flag=false;
for(k=j-1;k>=0;k--)

{
if(p[j]-p[k]>=j-k)

{
w[j]=j-k;
flag=true;
break;
}
}
if(flag==true)

{
continue;
}
else
w[j]=j+1;

}
for(int i=0;i<n;i++)
printf("%d ",w[i]);
printf("\n");
}
return 0;

}

]]>