Pagini recente » Cod sursa (job #1107542) | Cod sursa (job #287760) | Cod sursa (job #2431336) | Cod sursa (job #2021360) | Cod sursa (job #3191097)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("cc.in");
ofstream g("cc.out");
int main() {
int n, c, aux;
f >> n;
vector<vector<int>> costs(n);
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++) {
f >> c;
costs[i].push_back(c);
}
}
vector<int> matching(n, 0);
for(int i = 0; i < n; i++)
matching[i] = i;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(i != j){
//incercam sa schimba matching ai i -> matching[j] si j -> matching[i]
if(costs[i][matching[i]] + costs[j][matching[j]] > costs[i][matching[j]] + costs[j][matching[i]]){
aux = matching[i];
matching[i] = matching[j];
matching[j] = aux;
}
}
int s = 0;
for(int i = 0; i < n; i++)
s += costs[i][matching[i]];
g << s;
return 0;
}