2531

来源:互联网 发布:约瑟夫环算法 数组 编辑:程序博客网 时间:2024/04/30 15:33
#include<iostream>using namespace std;const int SIZE = 21;int QA[SIZE] = {0};int QB[SIZE] = {0};int map[SIZE][SIZE] = {0};int N = 0;int tem = 0;int sum = 0;void dfs(int a, int b, int step);int main(){freopen("input.txt", "r", stdin);setbuf(stdout, NULL);cin >> N;for(int i = 1; i <= N; i++){for(int j = 1; j <= N; j++){cin >> map[i][j];}}QA[0] = 1;dfs(1, 0, 1);cout << sum << endl;return 0;}void dfs(int a, int b, int step){if(step == N){tem = 0;for(int i = 0; i < a; i++){for(int j = 0; j < b; j++){tem += map[QA[i]][QB[j]];}}if(tem > sum){sum = tem;}return;}step++;QA[a] = step;dfs(a+1, b, step);QB[b] = step;dfs(a, b+1, step);}

0 0