-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva11553.cpp
More file actions
42 lines (38 loc) · 913 Bytes
/
uva11553.cpp
File metadata and controls
42 lines (38 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* Rishikesh
* UVA 11553 Grid Game
* Bob always chooses.
*/
#include<iostream>
#include<string>
#include<sstream>
#include<iomanip>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cstdint>
#include<numeric>
using namespace std;
int main() {
int ncases;
cin >> ncases;
while(ncases--) {
int n; cin >> n;
vector<vector<int>> grid(n, vector<int>(n));
vector<int> ind(n);
for(int i=0; i< n; i++)
for(int j = 0; j< n; j++)
cin >> grid[i][j];
iota(ind.begin(), ind.end(), 0);
int bestscore=1e9;
do {
int score = 0;
for (int i = 0; i< n; i++) {
score += grid[i][ind[i]];
}
bestscore = min(bestscore, score);
}while(next_permutation(ind.begin(), ind.end()));
cout << bestscore << endl;
}
}