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

     

  • 相关阅读:
    包装类
    String、Date、Calendar的转换
    枚举enum
    mybatis纵览
    postman编程
    postman导出Collection文件
    host头攻击
    maven处理jar包冲突
    jdk版本与项目依赖jar包不兼容
    linux安装jdk脚本
  • 原文地址:https://www.cnblogs.com/mohari/p/12969037.html
Copyright © 2011-2022 走看看