Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- typedef struct pos{
- int row;
- int col;
- }pos;
- int table[11][11];
- bool place[11];
- vector<pos> tmp;
- vector<pos> ans;
- int t, x, sum, mx;
- void PlaceRook(int row){
- if(row > t){
- if(sum > mx){
- ans.clear();
- ans = tmp;
- mx = sum;
- }
- return;
- } else {
- for(int i = 1; i <= t; ++i){
- if(!place[i]){
- sum += table[row][i];
- tmp.push_back({row, i});
- place[i] = true;
- PlaceRook(row + 1);
- sum -= table[row][i];
- tmp.pop_back();
- place[i] = false;
- }
- }
- return;
- }
- }
- void PrintTable(){
- for(int i = 1; i <= t; ++i){
- for(int j = 1; j <= t; ++j){
- cout << table[i][j] << " ";
- }
- cout << "\n";
- }
- }
- int main(){
- scanf("%d", &t);
- for(int i = 1; i <= t; ++i){
- for(int j = 1; j <= t; ++j){
- scanf("%d", &x);
- table[i][j] = x;
- }
- }
- mx = -2e9;
- sum = 0;
- PlaceRook(1);
- cout << mx << "\n";
- for(auto x : ans){
- cout << x.row << " " << x.col << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement