【暴力枚舉】二進制枚舉法-爐石傳說

【暴力枚舉】二進制枚舉法-爐石傳說

在這裏插入圖片描述
在這裏插入圖片描述

#include<iostream>
#define fcmin 1 // 一張隨從牌
#define Ap 10 // 10點法力值
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    // Input
    int n;  // 牌的數目
    cin >> n;
    int cards[n][3];
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < 3; ++j){
            cin >> cards[i][j];
        }
    }
    // Process
    // Judge_1
    int flag = 0; // 無隨從牌
    for(int i = 0; i < n; i++){
        if(!cards[i][1]){
            flag = 1;
            break;
        }
    }
    if(!flag || (n == 0)){
        cout << "0" << endl;
        return 0;
    }
    // Judge_2
    int max = 0;
    for(int i = 0; i < (1 << n); ++i){
        int consume = 0;
        int FL = 0;
        int num = 0;
        for(int j = 0; j < n; ++j){
            if(i & (1<<j)){
                FL += cards[j][2];
                consume += cards[j][0];
                if(cards[j][1] == 0)num++;
            }
        }
        if(consume <= Ap && num >=fcmin && FL > max){
            max = FL;
        }
    }
    cout << max << endl;
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章