全排列的使用
c++全排列 next_prenumation(a.begin(),a.end())
nextprenumation()就是该数组的下一个字典序大的排列,(更换最后一个逆序对)
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
struct node
{
int a, b, c;
} ;
bool st[13];
int main()
{
int t;
cin >> t;
while(t--)
{
int n, m;
cin >> n >> m;
vector<node> ti(n);
for (int i = 0; i < n;i++)
{
int a, b, c;
cin >> a >> b >> c;
ti[i] = {a, b, c};
}
vector<int> id(n);
for (int i = 0; i < id.size();i++)
id[i] = i;
int ans = 0;
do
{
int sum = 0, t = 0;
for (int i = 0; i < n;i++)
{
auto [a, b, c] = ti[id[i]];
t += b;
if(t>m)
break;
sum += max(a * 3 / 10, a - a * t / 250 - c * 50);
}
ans = max(ans, sum);
} while (next_permutation(id.begin(),id.end()));
cout << ans << endl;
}
}
浙公网安备 33010602011771号