网址如下:
暴力枚举就行了
每个行为的次数不超过3,因为当次数为4的时候,相当于没动
然后就开始枚举
代码如下:
#include<cstdio>
const int maxn = 9;
// A B C D E F G H I
int move[10][maxn]{{0, 0, 0, 0, 0, 0, 0, 0, 0},
{1, 1, 0, 1, 1, 0, 0, 0, 0},
{1, 1, 1, 0, 0, 0, 0, 0, 0},
{0, 1, 1, 0, 1, 1, 0, 0, 0},
{1, 0, 0, 1, 0, 0, 1, 0, 0},
{0, 1, 0, 1, 1, 1, 0, 1, 0},
{0, 0, 1, 0, 0, 1, 0, 0, 1},
{0, 0, 0, 1, 1, 0, 1, 1, 0},
{0, 0, 0, 0, 0, 0, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 0, 1, 1}};
struct Node{
int clock[maxn];
Node(){}
void get_next(int m, int num){
for(int i = 0; i < maxn; i++)
clock[i] = clock[i] + move[m][i] * num;
}
bool is_end(void){
for(int i = 0; i < maxn; i++)
if(clock[i] % 4) return false;
return true;
}
};
int ans[10];
Node beg, end;
bool get_permutation(int maxd, int cur, int d){
if(cur > maxn){
end = beg;
for(int i = 1; i <= maxn; i++) if(ans[i]) end.get_next(i, ans[i]);
return end.is_end();
}
for(int i = 0; i < 4; i++){
if(d + i > maxd) break;
ans[cur] = i;
if(get_permutation(maxd, cur + 1, d + i)) return true;
}
return false;
}
int main(void)
{
for(int i = 0; i < maxn; i++) scanf("%d", &beg.clock[i]);
for(int i = 0; i <= 27; i++) if(get_permutation(i, 1, 0)) break;
for(int i = 1; i <= maxn; i++)
if(ans[i]) while(ans[i]--) printf("%d ", i);
return 0;
}