#include #include #include #include #include #include #include using namespace std; struct Row { int row; int br; double secondHighestCost; double highestCost; double totalCost; int* actors; }; bool compareRowsByRow(const Row& r1, const Row& r2) { return r1.row > r2.row; } bool compareRowsByBr(const Row& r1, const Row& r2) { if (r1.br != r2.br) { return r1.br > r2.br; } return r1.row > r2.row; } bool compareRowsByHighestCost(const Row& r1, const Row& r2) { if (r1.highestCost != r2.highestCost) { return r1.highestCost > r2.highestCost; } return r1.row > r2.row; } bool compareRowsByTwoHighestCosts(const Row& r1, const Row& r2) { double c1 = r1.highestCost*2+r1.secondHighestCost; double c2 = r2.highestCost*2+r2.secondHighestCost; if (c1 != c2) { return c1 > c2; } return r1.row > r2.row; } bool compareRowsByTotalCost(const Row& r1, const Row& r2) { if (r1.totalCost != r2.totalCost) { return r1.totalCost > r2.totalCost; } return r1.row > r2.row; } bool contains(int* a, int br, int aa) { for (int i=0;i rows) { double cost = 0; for (int i=0;i>n>>m; double* c = new double[n]; for (int i = 0; i < n; ++i) { inp>>c[i]; } std::vector rows(m); std::vector bestRows(m); for (int i = 0; i < m; ++i) { inp>>rows[i].br; rows[i].row = i + 1; rows[i].actors = new int[rows[i].br]; rows[i].highestCost = 0; rows[i].totalCost = 0; for (int j = 0; j < rows[i].br; ++j) { int actor; inp>>actor; actor--; rows[i].actors[j] = actor; if (c[actor]>rows[i].highestCost) { rows[i].secondHighestCost = rows[i].highestCost; rows[i].highestCost = c[actor]; } rows[i].totalCost += c[actor]; } } inp.close(); std::sort(rows.begin(), rows.end(), compareRowsByHighestCost); double cost = costFunctionV(n,m,c,rows); double bestCost = cost+1; if (cost bestRowsPivot = bestRows = rows; // !!! while(t<4600 && std::next_permutation(rows.begin(), rows.end(), compareRowsByRow)) { double cost = costFunctionV(n,m,c,rows); if (cost