zoj1134 Strategic Game(DP/图论)
2011-08-18 01:55
351 查看
/*
简单的树形DP:利用搜索正向求解。
0的孩子必须是1,1的孩子任意,取最小的。
*/
View Code
简单的树形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; }
相关文章推荐
- ZOJ 1134 Strategic Game(树形DP)
- ZOJ 1134 Strategic Game(树形DP)
- ZOJ1134 POJ1463 HDU1054 Strategic Game, 树形DP
- ZOJ 1134 Strategic Game 树的最大独立集
- zoj 1134 - Strategic Game
- zoj 1134 - Strategic Game
- ZOJ 1134 Strategic Game(非二分图最小顶点覆盖)
- zoj2711 Regular Words(DP)
- zoj 3471 Most Powerful //状态压缩DP
- POJ 1463 Strategic game (树形dp 树的最小点覆盖 水)
- ZOJ 3537 Cake (区间DP,三角形剖分)
- ZOJ 3781 Paint the Grid Reloaded 图论 bfs
- ZOJ 3689 Digging(DP)
- ZOJ 3329 One Person Game 【期望dp】
- zoj 3381(DP+RMQ)
- Food Delivery - ZOJ 3469 dp
- zoj 3545 AC自动机+状态dp
- (树形DP) Strategic game(P1463)
- zoj 3822 Domination 概率DP
- ZOJ 2366 Weird Dissimilarity (简单DP)