标题: 由农心杯想到个数学问题, 胜负组合问题
性别:未知-离线 风精之羽

Rank: 9Rank: 9Rank: 9
组别 校尉
级别 安南将军
功绩 20
帖子 2959
编号 31482
注册 2005-1-30
家族 轩辕丐帮


发表于 2008-4-13 15:11 资料 文集 短消息 看全部作者
我写了个程序算了下,结果是57840480000种,我把程序贴出来,大家帮忙看看逻辑上有没错误?
用duizhen函数对顶楼的duizhen(1,2,2,0)情况运算结果也为26。

double duizhen(double x1,double x2,double x3,int flag);

main()
{
double number;
number=3*25*duizhen(5,5,5,0); /*三国出场顺序有3种,首轮对手选择方式有25种。*/
printf("%lf",number);
getch();
}

double duizhen(double x1,double x2,double x3,int flag)      /*flag=0表示1,2对阵,flag=1表示1,3对阵,flag=2表示2,3对阵*/
{
double num=1;
if(x1>0&&x2>0&&x3>0)
        {
        if(flag==0)
                {
                num=x3*(duizhen(x1,x2-1,x3,1)+duizhen(x1-1,x2,x3,2));
                }
        else if(flag==1)
                {
                num=x2*(duizhen(x1,x2,x3-1,0)+duizhen(x1-1,x2,x3,2));
                }
        else if(flag==2)
                {
                num=x1*(duizhen(x1,x2,x3-1,0)+duizhen(x1,x2-1,x3,1));
                }
        }
else if(x1==0&&x2>0&&x3>0)
        {
        if(x2>1&&x3>1)
                {
                num=(x2-1)*duizhen(x1,x2-1,x3,0)+(x3-1)*duizhen(x1,x2,x3-1,0);
                }
        else if(x2==1&&x3>1)
                {
                num=1+(x3-1)*duizhen(x1,x2,x3-1,0);
                }
        else if(x3==1&&x2>1)
                {
                num=1+(x2-1)*duizhen(x1,x2-1,x3,0);
                }
        else if(x3==1&&x2==1)
                {
                num=2;
                }
        }
else if(x2==0&&x1>0&&x3>0)
        {
        if(x1>1&&x3>1)
                {
                num=(x1-1)*duizhen(x1-1,x2,x3,0)+(x3-1)*duizhen(x1-1,x2,x3,0);
                }
        else if(x1==1&&x3>1)
                {
                num=1+(x3-1)*duizhen(x1,x2,x3-1,0);
                }
        else if(x3==1&&x1>1)
                {
                num=1+(x1-1)*duizhen(x1-1,x2,x3,0);
                }
        else if(x1==1&&x3==1)
                {
                num=2;
                }
        }
else if(x3==0&&x1>0&&x2>0)
        {
        if(x1>1&&x2>1)
                {
                num=(x1-1)*duizhen(x1-1,x2,x3,0)+(x2-1)*duizhen(x1,x2-1,x3,0);
                }
        else if(x1==1&&x2>1)
                {
                num=1+(x2-1)*duizhen(x1,x2-1,x3,0);
                }
        else if(x2==1&&x1>1)
                {
                num=1+(x1-1)*duizhen(x1-1,x2,x3,0);
                }
        else if(x1==1&&x2==1)
                {
                num=2;
                }
        }
return num;
}

[ 本帖最后由 风精之羽 于 2008-4-13 16:41 编辑 ]


顶部

正在浏览此帖的会员 - 共 1 人在线




当前时区 GMT+8, 现在时间是 2025-2-10 02:13
京ICP备2023018092号 轩辕春秋 2003-2023 www.xycq.org.cn

Powered by Discuz! 5.0.0 2001-2006 Comsenz Inc.
Processed in 0.009234 second(s), 9 queries , Gzip enabled

清除 Cookies - 联系我们 - 轩辕春秋 - Archiver - WAP