标签:
汉诺塔的规则这里就不再多说了,详见题目:汉诺塔(一)
现在假设规定要把所有的金片移动到第三个针上,给你任意一种处于合法状态的汉诺塔,你能计算出从当前状态移动到目标状态所需要的最少步数吗?
2 3 1 1 1 3 1 1 3
7 3
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x) memset(x,0,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ")
#define T_T while(T--)
const int MAXN=40;
int a[MAXN];
int ans;
int main(){
int T,n;
SI(T);
T_T{
ans=0;
SI(n);
for(int i=1;i<=n;i++)SI(a[i]);
int cur=3;
for(int i=n;i>0;i--){
if(a[i]!=cur){
cur=6-a[i]-cur;
ans+=1<<(i-1);
}
}
printf("%d\n",ans);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/5170661.html