#include #include const int UP =0; const int LEFT =1; const int RIGHT=2; const int DOWN =3; const int maxn =70+5; int d[maxn][4][4][3]; int action[maxn][4][4][3]; char str[maxn],hsh[128],fth[]=".LR"; inline int energy(int a,int ta) { if(a==ta) return 3; if(a+ta==3) return 7; return 5; } int energy(int i,int a,int b,int s,int f,int t,int& ta,int& tb) { ta=a;tb=b; if(f==1) ta=t; else if(f==2) tb=t; if(ta==tb) return -1;//the same position if(ta==RIGHT&&tb==LEFT) return -1;//turned around if(a==RIGHT&&tb!=b) return -1; if(b==LEFT&&ta!=a) return -1;//bad action int e; if(f==0) e=0; else if(f!=s) e=1; else { if(f==1) e=energy(a,ta); else e=energy(b,tb); } return e; } void update(int i,int a,int b,int s,int f,int t) { int ta,tb; int e=energy(i,a,b,s,f,t,ta,tb); if(e<0) return;//bad action int cost=d[i+1][ta][tb][f]+e; int &res=d[i][a][b][s]; if(cost=0;i--) for(a=0;a<4;a++) for(b=0;b<4;b++) if(a!=b) for(s=0;s<3;s++) { d[i][a][b][s]=10*n; if(str[i]=='.') { update(i,a,b,s,0,0); for(t=0;t<4;t++) { update(i,a,b,s,LEFT ,t); update(i,a,b,s,RIGHT,t); } } else { update(i,a,b,s,LEFT ,hsh[str[i]]); update(i,a,b,s,RIGHT,hsh[str[i]]); } } a=LEFT,b=RIGHT,s=0; for(i=0;i