一共10个电门,穷举310次
#include<stdio.h>
#include<math.h>
int main(){
int a[5][5], max = (int)pow(3, 10), t, op, count = 0;
a[0][0] = a[0][2] = a[0][4] = 1;
a[0][1] = a[0][3] = 0;
for(int k = 0; k < max; k++){
t = k;
for(int i = 1; i < 5; i++){
for(int j = 0; j < 5 - i; j++){
op = t % 3;
t /= 3;
switch(op){
case 0 : a[i][j] = a[i-1][j] & a[i-1][j+1]; break;
case 1 : a[i][j] = a[i-1][j] | a[i-1][j+1]; break;
case 2 : a[i][j] = a[i-1][j] ^ a[i-1][j+1];
}
}
}
if(a[4][0] == 1) count++;
}
printf("%d", count);//30528
return 0;
}