#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STEP 20
//index: 0 - ç¼ï¼1ï¼ç¾ï¼2ï¼èï¼3ï¼å夫ï¼valueï¼0ï¼æ¬å²¸ï¼1ï¼å¯¹å²¸
int a[MAX_STEP][4];
int b[MAX_STEP];
char *name[] = { "空æ", "带ç¼", "带ç¾", "带è" };
void search(int iStep) { int i; if (a[iStep][0] + a[iStep][1] + a[iStep][2] + a[iStep][3] == 4) { for (i = 0; i < iStep; i++) { if (a[i][3] == 0) { printf("%så°å¯¹å²¸\n", name[b[i] + 1]); } else { printf("%såæ¬å²¸\n", name[b[i] + 1]); } } printf("\n"); return; } for (i = 0; i < iStep; i++) { if (memcmp(a[i], a[iStep], sizeof(a[i])) == 0) { return; } } if (a[iStep][1] != a[iStep][3] && (a[iStep][2] == a[iStep][1] || a[iStep][0] == a[iStep][1])) { return; } for (i = -1; i <= 2; i++) { b[iStep] = i; memcpy(a[iStep + 1], a[iStep], sizeof(a[iStep + 1])); a[iStep + 1][3] = 1 - a[iStep + 1][3]; if (i == -1) { search(iStep + 1); } else if (a[iStep][i] == a[iStep][3]) { a[iStep + 1][i] = a[iStep + 1][3]; search(iStep + 1); } } } int main() { search(0); return 0; }
追é®å¥ä»¬å¿ãä½ è¿ä¹å¤ªä¹±äºç¹å¿ãè¿æ²¡æ注éåã
追çå.......