题解分享
题解分享简介
李白打酒(结果填空) - 题解
```cpp
#include <iostream>
#include <set>
#include <functional>
#include <string>
using namespace std;
int main() {
int jv = 2;
int dian = 0; // 店
int hua = 0; // 花
set<string> res; // 使用 out 或者 set.size( ) 计数都可以
string s;
int out;
function<void()> dfs = [&]() {
if (jv < 0 || dian > 5 || hua > 10)
return;
if (jv == 0 && dian == 5 && hua == 10 && s[s.size() - 1] == 'b') {
res.insert(s);
++out;
cout << s << '\n';
return;
}
s += 'a';
++dian;
jv *= 2;
dfs();
--dian;
jv /= 2;
s.pop_back();
s += 'b';
++hua;
--jv;
dfs();
--hua;
++jv;
s.pop_back();
};
dfs();
cout << res.size() << ' ' << out;
return 0;
}
```
查看全文
0
0
1
1
李白打酒(结果填空) - 题解
```
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110, MOD = 1000000007;
int f[N][N][N];
int n, m;
int main()
{
cin >> n >> m;
f[0][0][2] = 1;
for (int i = 0; i <= n; i ++ )
for (int j = 0; j <= m; j ++ )
for (int k = 0; k <= m; k ++ )
{
int& v = f[i][j][k];
if(i>=1 && k%2==0) v = (v + f[i - 1][j][k/2])%MOD;
if(j>=1) v = (v + f[i][j - 1][k + 1])%MOD;
}
cout << f[n][m - 1][1];
return 0;
}
```
查看全文
0
0
1
1
李白打酒(结果填空) - 题解
随便写的,答案正确了,不知道对不对
```
public class Main {
public static void main(String[] args) {
// 从结尾出发
// 最后一次是喝酒(b)
int res = sum(0, 1, 1);
System.out.println(res);
}
/**
*
* @param a 遇店次数
* @param b 遇花次数
* @param res 酒壶剩余酒量
* @return
*/
static int sum(int a, int b, int rest) {
if (a == 5 && b == 10 && rest == 2) {// 终止条件
return 1;
}
int ans = 0;
if (a + 1 <= 5 && rest % 2 == 0) {
// 买酒
ans += sum(a + 1, b, rest / 2);
}
if (b + 1 <= 10) {
//喝酒
ans += sum(a, b + 1, rest + 1);
}
return ans;
}
}
```
查看全文
0
0
1
1
李白打酒(结果填空) - 题解
```Java
static Set<String> ans = new HashSet<>();
public static void main(String[] args) throws IOException {
solution("", 2, 0, 0);
System.out.println(ans.size());
}
static void solution(String path, int booze, int store, int flower) {
if (booze == 0 && flower == 10 && store ==5) {
ans.add(path);
} else if (booze <= 0 || flower > 10 || store > 5) {
} else {
solution(path + "b", booze - 1, store, flower + 1);
solution(path + "a", booze * 2, store + 1, flower);
}
}
```
查看全文
0
0
0
6
李白打酒(结果填空) - 题解
```
#include <iostream>
using namespace std;
int res;
void dfs(int d,int h,int j)
{
if(d==5 && h==10 && j==0)
{
res++;
return;
}
if(j==0) return;
if(d<5) dfs(d+1,h,j*2);
if(h<10) dfs(d,h+1,j-1);
}
int main()
{
dfs(0,0,2);
cout<<res;
return 0;
}
```
查看全文
0
0
0
0
李白打酒(结果填空) - 题解
```
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 20
char path[N];
int numa,numb,sum,cnt;
void dfs(int u)
{
if(u==14)
{
numa=0;numb=0;sum=2;
for(int i=0;i<14;i++)
{
if(path[i]=='a')
{
numa++;
sum*=2;
}
else
{
numb++;
sum--;
}
}
if(sum==1&&numa==5&&numb==9)
{
for(int i=0;i<14;i++)cout<<path[i];
cout<<endl;
cnt++;
}
return ;
}
path[u]='a';
dfs(u+1);
path[u]='b';
dfs(u+1);
}
int main()
{
dfs(0);
cout<<cnt<<endl;
return 0;
}
```
查看全文
0
0
0
0



