题解:建两棵树然后深搜遍历,需要注意在深搜的函数里随着树的层次变深,每个黑色小方块的值也在不断减小,所以累加的值是 1024 / pow (4, l),l是数的深度。
#include <cstdio>
#include <string>
#include <iostream>
#include <cmath>
using namespace std;
const int N = 10010;
struct Node {
char c;
Node* s[4];
Node() {
c = '\0';
s[0] = s[1] = s[2] = s[3] = NULL;
}
};
int len, sum, i;
Node* build(string str) {
i++;
if (i == len)
return NULL;
Node* node = new Node;
node -> c = str[i];
if (node -> c == 'p') {
node -> s[0] = build(str);
node -> s[1] = build(str);
node -> s[2] = build(str);
node -> s[3] = build(str);
}
return node;
}
void dfs(Node* node1, Node* node2, int l) {
if (node1