栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1134 Strategic Game

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1134 Strategic Game

#include <stdio.h>#include <stdlib.h>#include <string.h>#define min(x,y) ((x)<(y)?(x):(y))typedef struct node{    int Count;    int Value;    int    Next[ 10 ];}node;node Node[ 1510 ];int  Root;typedef struct answ{    int sum0;    int sum1;}Answ;Answ Save;Answ dp( int Root ){    Answ an;         an.sum0 = 0;         an.sum1 = 1;    if ( Node[ Root ].Count ) {        for ( int i = 0 ; i < Node[ Root ].Count ; ++ i ) { Save = dp( Node[ Root ].Next[ i ] ); an.sum0 += Save.sum1; an.sum1 += min( Save.sum0, Save.sum1 );        }    }    return an;}int main(){    int n,a,m,b;    while ( scanf("%d",&n) != EOF ) {        Root = -1;         memset( Node, 0, sizeof( Node ) );        for ( int i = 0 ; i < n ; ++ i ) { scanf("%d:(%d)",&a,&m);  if ( Root == -1 ) Root = a; Node[ a ].Count = m; Node[ a ].Value = a; for ( int j = 0 ; j < m ; ++ j ) {     scanf("%d",&b);     Node[ a ].Next[ j ] = b; }        }        Answ answer = dp( Root );        printf("%dn",min( answer.sum0, answer.sum1 ));    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/378191.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号