您的位置:首页 > 其它

zoj1134 Strategic Game(DP/图论)

2011-08-18 01:55 351 查看
/*
简单的树形DP:利用搜索正向求解。
0的孩子必须是1,1的孩子任意,取最小的。
*/

View Code

#include <stdio.h>
#include <stdlib.h>

typedef struct node
{
int     Point;
node*    Next;
}node;
node  Node[ 3001 ];
node *Head[ 1501 ];
bool  Used[ 1501 ];
int   Result[ 1501 ];

bool find( int a, int n )
{
for ( node *P = Head[ a ] ; P ; P = P->Next )
if ( !Used[ P->Point ] ) {
Used[ P->Point ] = true;
if ( Result[ P->Point ] == -1 || find( Result[ P->Point ] , n ) ) {
Result[ P->Point ] = a;
return true;
}
}
return false;
}

int argument( int n )
{
for ( int i = 0 ; i < n ; ++ i )
Result[ i ] = -1;
int Count = 0;
for ( int i = 0 ; i < n ; ++ i ) {
for ( int j = 0 ; j < n ; ++ j )
Used[ j ] = false;
if ( find( i, n ) )
++ Count;
}
return Count;
}

int main()
{
int n,a,m,b;
while ( scanf("%d",&n) != EOF ) {
for ( int i = 0 ; i < n ; ++ i )
Head[ i ] = NULL;
int Count = 0;
for ( int i = 0 ; i < n ; ++ i ) {
scanf("%d:(%d)",&a,&m);
for ( int j = 0 ; j < m ; ++ j ) {
scanf("%d",&b);
Node[ Count ].Next  = Head[ a ];
Node[ Count ].Point = b;
Head[ a ] = &Node[ Count ++ ];
Node[ Count ].Next  = Head[ b ];
Node[ Count ].Point = a;
Head[ b ] = &Node[ Count ++ ];
}
}
printf("%d\n",argument( n )/2);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: