#include #include  using namespace std;int lefts[20], rights[20], father[20]; string s1, s2, s3;int n, ans;void calc(int x, int dep){\tans = ans   dep*(s1[x] - 'A'   1);\tif (lefts[x] >= 0) calc(lefts[x], dep 1); \tif (rights[x] >= 0) calc(rights[x], dep 1);}void check(int x){\tif (lefts[x] >= 0) check(lefts[x]); \ts3 = s3   s1[x];\tif (rights[x] >= 0) check(rights[x]);}void dfs(int x, int th){\tif (th == n)\t{\t\ts3 = "";\t\tcheck(0);\t\tif (s3 == s2)\t\t{\t\t\tans = 0;\t\t\tcalc(0, 1); \t\t\tcout<= 0)\t\tdfs(father[x], th);}int main(){\tcin>>s1; \tcin>>s2;\tn = s1.size();\tmemset(lefts, -1, sizeof(lefts));\tmemset(rights, -1, sizeof(rights));\tmemset(father, -1, sizeof(father));\tdfs(0, 1);}

输入:

ABCDEF

BCAEDF

输出:

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部