View Code of Problem 1081

#include <bits/stdc++.h>
using namespace std;

int a[12][12];
bool vis[12];
int n, ans;

void dfs(int cnt, int sum){
    if(cnt == n){
        ans = max(ans, sum);
        return ;
    }
    for(int i=1; i<=n; i++){
        if(!vis[i])
            for(int j=i+1; j<=n; j++){
                if(!vis[j]){
                    vis[i] = vis[j] = true;
                    dfs(cnt + 2, sum + a[i][j]);
                    vis[i] = vis[j] = false;
                }
            }
    }
}

int main(){
    #ifdef sxk
        freopen("in.txt", "r", stdin);
    #endif // sxk

    while(~scanf("%d", &n) && n){
        for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++) scanf("%d", &a[i][j]);
        memset(vis, false, sizeof(vis));
        ans = 0;
        dfs(0, 0);
        printf("%d\n", ans);
    }
    return 0;
}

/*
F:\temp\16139774.54791\Main.cc:2:25: error: bits/stdc++.h: No such file or directory
F:\temp\16139774.54791\Main.cc: In function 'void dfs(int, int)':
F:\temp\16139774.54791\Main.cc:11: error: 'max' was not declared in this scope
F:\temp\16139774.54791\Main.cc: In function 'int main()':
F:\temp\16139774.54791\Main.cc:31: error: 'scanf' was not declared in this scope
F:\temp\16139774.54791\Main.cc:34: error: 'memset' was not declared in this scope
F:\temp\16139774.54791\Main.cc:37: error: 'printf' was not declared in this scope
*/

Double click to view unformatted code.


Back to problem 1081