您的位置:首页 > 其它

汉诺塔VII

2016-07-04 17:55 274 查看
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=2&problemid=3

每次最大的盘 只能放在a->c

#include<bits/stdc++.h>
using namespace std;
int f[30];
int dfs(int n,int a,int c,int b)
{
if(n<=0) return true;
if(f
==b) return false;
if(f
==a) return dfs(n-1,a,b,c);
return dfs(n-1,b,c,a);
}
int main()
{
int i,j,k,m,n,t,ans,tmp;

cin>>t;
while(t--)
{
cin>>n;
for(i=0;i<3;i++)
{
cin>>m;
for(j=0;j<m;j++) cin>>tmp,f[tmp]=i;
}
if(dfs(n,0,2,1)) cout<<"true"<<endl;
else cout<<"false"<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: