islands打炉石传说
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node
{
int cost, d, w;
};
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<node> v(n);
for (int i = 0; i < n; i++)
{
cin >> v[i].cost;
cin >> v[i].d;
cin >> v[i].w;
}
int ans = 0;
for (int i = 0; i < (1 << n); ++i)
{
int sum1 = 0;
int sum2 = 0;
int cost_cnt = 0;
for (int j = 0; j < n; j++)
{
if (i & (1 << j))
{
cost_cnt += v[j].cost;
if (v[j].d == 1)
sum2 += v[j].w;
else
sum1 += v[j].w;
}
}
if (cost_cnt > 10)
continue;
else
{
if (sum1 > 0)
sum1 += sum2;
ans = max(ans, sum1);
}
}
cout << ans;
return 0;
}