题目分析:
- 会增加ai的财富,消耗bi的魔法
- 回复ci的魔法,但减少di的财富
- 从1到n进行深搜,枚举所有情况,然后到最后去最大值
代码如下:
#include<bits/stdc++.h>
using namespace std;
#define mm(a,x) memset(a,x,sizeof a)
#define mk make_pair
#define ll long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define lowbit(x) (x) & (-x)
const int N = 20;
int n;
struct Node{
ll a,b,c,d;
}node[N];
ll ans;
void dfs(int u,ll money,ll magic){
if(u == n + 1){
ans = max(ans,money * magic);
return ;
}
ll t = magic - node[u].b;
if(t < 0) t = 0;
dfs(u + 1,money + node[u].a,t);
t = money - node[u].d;
if(t < 0) t = 0;
dfs(u + 1,t,magic + node[u].c);
}
int main() {
cin >> n;
for(int i = 1; i <= n; i ++ ){
ll a,b,c,d; cin >> a >> b >> c >> d;
node[i] = {a,b,c,d};
}
dfs(1,0,0);
cout<<ans;
return 0;
}