贪吃的小J
https://www.luogu.com.cn/problem/P4817
# Description
现在小J的胃的容量为0,她每吃一个orange,容量就会增加A;每吃一个lemon,饱食度就会增加B。小J还有一次喝水的机会,如果小J喝水前饱食度为x,喝水后饱食度会变为trunc(x/2)
小J的胃的容量不能超过T,否则肚子会爆炸。
试求小J的胃的容量最大能达到多少。
# Format
## Input
一行给出三个数字T,A,B
1<=T<=5,000,000
1<=A,B<=T
## Output
如题
# Samples
```input1
8 5 6
```
```output1
8
```
//76分
#include <iostream>
using namespace std;
int t, a, b;
int ans;
inline int maxa(int a, int b) {
if (a > b)
return a;
return b;
}
void dfs(int food, bool flag) {
ans = maxa(ans, food);
if (t >= food + a)
dfs(food + a, flag);
if (t >= food + b)
dfs(food + b, flag);
if (! flag)
dfs(food >> 1, flag ^ 1);
return ;
}
int main() {
cin >> t >> a >> b;
dfs(0, 0);
cout << ans << endl;
return 0;
}
//ac
#include <iostream>
using namespace std;
const int T = 5e6 + 7;
int t, a, b;
int ans;
int mem[T];
inline int maxa(int a, int b) {
if (a > b)
return a;
return b;
}
void dfs(int food, bool flag) {
if (mem[food])
return ;
mem[food] = 1;//就是这步!!
if (food > t)
return ;
ans = maxa(ans, food);
dfs(food + a, flag);
dfs(food + b, flag);
if (! flag)
dfs(food >> 1, flag ^ 1);
return ;
}
int main() {
cin >> t >> a >> b;
dfs(0, 0);
cout << ans << endl;
return 0;
}

浙公网安备 33010602011771号