当前位置:网站首页>Contest3145 - the 37th game of 2021 freshman individual training match_ C: Tour guide

Contest3145 - the 37th game of 2021 freshman individual training match_ C: Tour guide

2022-07-06 09:53:00 This question AC sleep again

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

const int MAXN=11;
int a[MAXN][MAXN];
bool used[MAXN];
int n,ans;

void init()
{
    memset( a,0,sizeof( a ) );
    memset( used,0,sizeof( used ) );
    ans=0;
}

//  Judgment No.  x  A student   The current total is  sum
void dfs( int x,int sum )
{
    if( x==n ) { ans=max( ans,sum ); return ; }

    int i,j;

    for( i=x;i<n;i++ )
    {
        for( j=0;j<n;j++ )
        {
            if( used[j]==false )
            {
                used[j]=true;
                dfs( i+1,sum+a[i][j] );
                used[j]=false;
            }
        }
    }
}

int main()
{
    int i,j; init();

    while( ~scanf("%d",&n) )
    {
        for( i=0;i<n;i++ )
        {
            for( j=0;j<n;j++ )
            {
                scanf("%d",&a[i][j]);
            }
        }
        dfs( 0,0 );

        printf("%d\n",ans);

        init();
    }
    return 0;
}

原网站

版权声明
本文为[This question AC sleep again]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131738367611.html