ACM PKU 2531 Network Saboteur http://acm.pku.edu.cn/JudgeOnline/problem?id=2531

先找出在一个集合中的所有点再根据标记来求最大值!做了这么久,也实属无奈!!!
#include <iostream>
using namespace std;

int Case;
int num[21][21];
bool flag[21];
int Max = 0;

int solve(int dp,int st)
{   
int i, j, k;
if (dp==0)
{
   int sum=0;
   for (j = 0;j < Case; j++)
   {
    if (flag[j] == 1)
    {
     for (k = 0;k < Case; k++)
     {
      if (flag[k] != 1)
       sum +=num[j][k]; 
     }
    }
   }
   if (sum > Max)
    Max = sum;
   return 0; 
}
for (i = st; i < Case; i++)
{
   flag[i] = 1;
   solve(dp-1, i+1); 
   flag[i] = 0;
}
return 0;
}

int main ()
{
int i, j;
    cin >> Case;
for (i = 0; i < Case; i++)
   for (j = 0; j < Case; j++)
    scanf("%d",&num[i][j]);
   for (i = 1; i <= Case/2; i++)   
   {
    memset(flag,0,sizeof(flag));
    solve(i, 0);
   }
  
   cout << Max << endl;
   return 0;
}

posted on 2011-05-06 18:53  _Clarence  阅读(75)  评论(0编辑  收藏

导航

统计