暴力搜索

暴力搜素应该会写吧,这个。。。。
  
#include < string .h >
#include
< stdio.h >
int rec[ 8 ][ 8 ];
int s[ 8 ];
int n;
int min;
int max;
void Bscktrack( int cout);
int main()
{
int i,j;
while ( 1 )
{
scanf(
" %d " , & n);
if (n ==- 1 )
{
break ;
}
for (i = 1 ;i <= n;i ++ )
{
for (j = 1 ;j <= n;j ++ )
{
scanf(
" %d " , & rec[i][j]);
}
}

min
= 10000000 ;
Bscktrack(
1 );
printf(
" %d\n " ,min);
}
return 0 ;
}
void Bscktrack( int cout)
{
int i,j;
int temp;
if (cout > n)
{
max
= - 1000000 ;
memset(s,
0 , sizeof (s));
for (i = 1 ;i <= n;i ++ )
{
for (j = 1 ;j <= n;j ++ )
{
s[i]
+= rec[j][i];
}
if (s[i] > max)
{
max
= s[i];
}
// 减枝
if (min < max)
{
break ;
}
}
if (min > max)
{
min
= max;
}
return ;
}
for (i = 1 ;i <= n;i ++ )
{
temp
= rec[cout][n];
for (j = n;j >= 1 ;j -- )
{
rec[cout][j]
= rec[cout][j - 1 ];
}
rec[cout][
1 ] = temp;
Bscktrack(cout
+ 1 );
}
}

你可能感兴趣的:(搜索)