#include<stdio.h>
#include<string.h>
const int INF=10000006;
const int maxn=1005;
char ch[maxn];
int pre[maxn][maxn];
int dp[maxn][maxn];
int M1[maxn],id[maxn];
int n;
void init(){
for(int i=0;i<maxn;i++)
for(int j=0;j<maxn;j++)
dp[i][j]=INF;
memset(pre,-1,sizeof(pre));
}
int ans[maxn];
int main(){
int i,j,k;
while(scanf("%d",&n)!=EOF){
scanf("%s",ch);
init();
for(i=1;i<maxn;i++){
dp[0][i]=i;
}
for(i=1;i<n;i++){
for(j=1;j<=n;j++){
if(i==1){
if(ch[i-1]=='=' && dp[i][j]> dp[i-1][j]+j){
pre[i][j]=j;
dp[i][j]=dp[i-1][j]+j;
}else if(ch[i-1]== 'L' && dp[i][j]>dp[i-1][j+1]+j){
pre[i][j]=j+1;
dp[i][j]=dp[i-1][j+1]+j;
}else if(ch[i-1]== 'R' && dp[i][j]>dp[i-1][j-1]+j){
pre[i][j]=j-1<1?j-1:1;
dp[i][j]=dp[i-1][j-1]+j;
}
}else{
dp[i][j]=M1[j]+j;
pre[i][j]=id[j];
}
}
for(k=0;k<maxn;k++){
M1[k]=INF;
id[k]=0;
}
if(ch[i]=='L'){
for(k=n;k>=1;k--){
if(dp[i][k+1]<M1[k+1]){
M1[k]=dp[i][k+1];
id[k]=k+1;
}else{
M1[k]=M1[k+1];
id[k]=id[k+1];
}
}
}else if(ch[i]=='R'){
for(k=1;k<=n;k++){
if(dp[i][k-1]<M1[k-1]){
M1[k]=dp[i][k-1];
id[k]=k-1;
}else{
M1[k]=M1[k-1];
id[k]=id[k-1];
}
}
}else if(ch[i]=='='){
for(k=1;k<=n;k++){
id[k]=k;
M1[k]=dp[i][k];
}
}
}
int min=INF,mark=0;
for(i=1;i<=n;i++){
if(min>dp[n-1][i]){
min=dp[n-1][i];
mark=i;
}
}
int cnt=n-1;
while(mark!=-1){
ans[cnt]=mark;
mark=pre[cnt--][mark];
}
for(i=0;i<n;i++)
printf("%d ",ans[i]);
puts("");
}
return 0;
}
/*
10
RRRRRRRRR
2
R
5
RRL=
*/
Partial Teacher 67A
最新推荐文章于 2024-04-16 13:28:25 发布