NC53680 「金」点石成金
\(n<=15\),直接指数枚举就行,时间复杂度\(O(2^n)\)
const int N=20;
int a[N],b[N];
int c[N],d[N];
int n;
LL ans;
void dfs(int u,int wealth,int magic)
{
if(u == n)
{
ans=max(ans,(LL)wealth*magic);
return;
}
dfs(u+1,wealth+a[u],max(magic-b[u],0));
dfs(u+1,max(wealth-d[u],0),magic+c[u]);
}
int main()
{
cin>>n;
for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i]>>d[i];
dfs(0,0,0);
cout<<ans<<endl;
//system("pause");
}