Language: C++

//
// Created by tattsun on 2017/02/11.
//

#include <iostream>
#include <vector>
#include <algorithm>

#define DRUGS_NUM_MAX 40
#define TOTAL_COST_MAX DRUGS_NUM_MAX * 1000

using namespace std;

struct Drug {
    int a;
    int b;
    int cost;
};

int n;
int ma;
int mb;
Drug drugs[DRUGS_NUM_MAX];

int min(int a, int b) {
    if(a < b) return a;
    return b;
}

int gcd(int a, int b) {
    while(a != b) {
        if(a < b) b -= a;
        else a -= b;
    }
    return a;
}

int total_cost(vector<bool>& used_drugs) {
    int c = 0;
    for(int i=0; i<n; i++) {
        if(used_drugs[i])
            c += drugs[i].cost;
    }
    return c;
}

bool is_achieved(vector<bool>& used_drugs) {
    int a = 0, b = 0;
    for(int i=0; i<n; i++) {
        if(used_drugs[i]) {
            a += drugs[i].a;
            b += drugs[i].b;
        }
    }

    int g = gcd(a, b);
    a = a / g;
    b = b / g;

    return a == ma && b == mb;
}

vector<vector<bool>> dp;
vector<int> cost;

int _solve(int d, vector<bool>& used_drugs) {
    used_drugs[d] = true;

    for(int i=0; i<dp.size(); i++) {
        bool ok = true;
        for(int j=0; j < dp[i].size(); j++) {
            if(dp[i][j] != used_drugs[j]) {
                ok = false;
            }
        }
        if(ok) return cost[i];
    }

    int min_cost = TOTAL_COST_MAX;
    if(is_achieved(used_drugs)) min_cost = total_cost(used_drugs);

    for(int i=0; i<n; i++) {
        if(used_drugs[i] == true) {
            continue;
        }

        int c = _solve(i, used_drugs);
        if(c == -1) continue;
        min_cost = min(min_cost, c);
    }

    used_drugs[d] = false;
    dp.push_back(used_drugs);
    dp.push_back(cost);

    if(min_cost == TOTAL_COST_MAX)
        return -1;
    else
        return min_cost;
}

int solve() {
    vector<bool> used_drugs;
    for(int i=0; i<n; i++) {
        used_drugs.push_back(false);
    }

    int min_cost = TOTAL_COST_MAX;
    for(int i=0; i<n; i++) {
        int c = _solve(i, used_drugs);
        min_cost = min(min_cost, c);
    }
    if(min_cost == TOTAL_COST_MAX) return -1;
    return min_cost;
}

int main() {
    cin >> n >> ma >> mb;
    int g = gcd(ma, mb);
    ma = ma / g;
    mb = mb / g;

    int a, b, cost;
    for(int i=0; i<n; i++) {
        cin >> a >> b >> cost;
        drugs[i].a = a;
        drugs[i].b = b;
        drugs[i].cost = cost;
    }

    cout << solve() << endl;
}

Compiler output:
a.cc: In function 'int _solve(int, std::vector<bool>&)':
a.cc:94:17: error: no matching function for call to 'std::vector<std::vector<bool> >::push_back(std::vector<int>&)'
   94 |     dp.push_back(cost);
      |     ~~~~~~~~~~~~^~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:6:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::vector<bool>; _Alloc = std::allocator<std::vector<bool> >; value_type = std::vector<bool>]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const std::vector<std::vector<bool> >::value_type&' {aka 'const std::vector<bool>&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::vector<bool>; _Alloc = std::allocator<std::vector<bool> >; value_type = std::vector<bool>]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<std::vector<bool> >::value_type&&' {aka 'std::vector<bool>&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~