Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n,mx=-100000;
- int ar[11][11];
- int column[11],line[11];
- vector <int> x,y,ansx,ansy;
- void rook(int i,int j,int sum){
- if(sum>mx && j==n) {
- ansx=x;
- ansy=y;
- mx=sum;
- return ;
- }
- for(int I=1;I<=n;I++){
- if(I!=i && column[j+1]==0 && line[I]==0){
- column[j+1]++;
- line[I]++;
- x.push_back(I);
- y.push_back(j+1);
- rook(I,j+1,sum+ar[I][j+1]);
- x.pop_back();
- y.pop_back();
- column[j+1]--;
- line[I]--;
- }
- }
- }
- int main(){
- scanf("%d",&n);
- for(int i=1;i<=n;i++){
- for(int j=1;j<=n;j++){
- column[j]=0;
- line[i]=0;
- scanf("%d",&ar[i][j]);
- }
- }
- for(int i=1;i<=n;i++){
- column[1]++;
- line[i]++;
- x.push_back(i);
- y.push_back(1);
- rook(i,1,ar[i][1]);
- x.pop_back();
- y.pop_back();
- column[1]--;
- line[i]--;
- }
- printf("%d\n",mx);
- for(int i=0;i<ansx.size();i++){
- printf("%d %d\n",ansx[i],ansy[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement