其他分享
首页 > 其他分享> > NC53680 「金」点石成金

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");
}

标签:magic,wealth,int,max,dfs,ans,NC53680,点石成金
来源: https://www.cnblogs.com/fxh0707/p/13757433.html