李白打酒有什么解法

• 17

``````话说大诗人李白，一生好饮。幸好他从不开车。

``````

4 个回答
✓ 已被采纳

1. bababaababbbbbb

2. babaabbabbabbbb

3. babaababbbbbabb

4. baabbbaabbabbbb

5. baabbabbbaabbbb

6. baabbabbabbbabb

7. baababbbbbababb

8. abbbabaabbabbbb

9. abbbaabbbaabbbb

10. abbbaabbabbbabb

11. abbabbbabaabbbb

12. abbabbbaabbbabb

13. abbabbabbbababb

14. ababbbbbabababb

• 正向：从`(花,店,酒) = (0,0,2)`出发，递归到`(10,5,0)`结束。

• 反向：从`(10,5,0)`倒推，`(10,5,0) -> (9,5,1) -> (8,5,2)` ……直到`(0,0,2)`结束。

leo126
• 1
``````#include <cstdio>

int count=0;

void dfs(int a, int b, int wine) {
//    printf("%d %d %d\n",a, b, wine);
if(!a && !b && wine == 1) count++;
else {
b--; wine--;
if(a >= 0 && b >= 0 && wine >= 1)
dfs(a, b, wine);

b++; wine++;

a--; wine *= 2;
if(a >= 0 && b >= 0 && wine >= 1)
dfs(a, b, wine);

a++; wine /= 2;
}
}

int main() {
int a=5, b=9, wine=2;

dfs(a, b, wine);

printf("%d\n",count);
return 0;
} ``````

``````int ans = 0;
for (int i = 0; i < (1<<14); ++i) {
int tot_1 = 0;
int tot_0 = 0;
int num = 2;
for (int j = 0; j < 14; ++j) {
if (i&(1 << j)) { // 这里判断二进制 i 从右数第 j + 1位是否为1
tot_1++;
num = num*2;
} else {
tot_0++;
num = num - 1;
}
}
if (tot_1 == 5 && tot_0 == 9 && num == 1) {
++ans; //记录合法方案书
}
}``````

你尚未登录，登录后可以
• 和开发者交流问题的细节
• 关注并接收问题和回答的更新提醒
• 参与内容的编辑和改进，让解决方法与时俱进