zoukankan      html  css  js  c++  java
  • 「金」点石成金(dfs)

    传送门

    题目大意:每次有两种选择,第一种是得到金钱,消耗魔法值。第二种是得到魔法值,消耗金钱。金钱和魔法值不够消耗时也可以消耗,该值置为0。求金钱*魔法值的最大值。

    题解:范围很小,直接dfs爆搜即可。

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=20;
    typedef long long ll;
    struct node{
        ll a,b,c,d;
    }tot[maxn];
    ll ans,maxx=-0x3f3f3f;
    int n;
    void dfs(int k,ll m,ll c){
        if(k==n){
            ans=m*c;
            if(ans>maxx){
                maxx=ans;
            }
            return ;
        }
        if(c>tot[k].b)dfs(k+1,m+tot[k].a,c-tot[k].b);
        else dfs(k+1,m+tot[k].a,0);
        if(m>tot[k].d)dfs(k+1,m-tot[k].d,c+tot[k].c);
        else dfs(k+1,0,c+tot[k].c);
    }
    int main(){
        cin>>n;
        for(int i=0;i<n;i++){
            scanf("%ld%ld%ld%ld",&tot[i].a,&tot[i].b,&tot[i].c,&tot[i].d);
        }
        dfs(0,0,0);
        cout<<maxx<<endl;
        return 0;
    }
    View Code

     

  • 相关阅读:
    webServer xampp的安装及使用
    javascript 原生方法监听DOM结构改变事件
    c# 文件简繁体转换
    c# 网络是否连接
    JMS
    JMS
    JMS
    Quartz Scheduler(2.2.1)
    MySQL
    Git CMD
  • 原文地址:https://www.cnblogs.com/mohari/p/12969037.html
Copyright © 2011-2022 走看看