猫和老鼠玩象棋,玩了M+N局,猫赢了M局 老鼠赢了N局 N>M,而且在整个过程中,猫的得分从来没有超过过老鼠,问共有多少种可能的比赛得分过程

1. 猫和老鼠玩象棋,玩了M+N局,猫赢了M局 老鼠赢了N局 N>M,而且在整个过程中,猫的得分从来没有超过过老鼠,问共有多少种可能的比赛得分过程

 

2. 每日早上淘宝网办公楼对面的烧饼店都有人排长队买烧饼,假设每个烧饼5元,有16个人排队,其中有8个人只有5元的钞票,另外8个人只有10¥的钞票,每个人只买一个烧饼。假设开始时店老板没有任何钞票,问这16个人有多少种排队方式,不至于使店老板找不开钱???

 

same question, VB.NET codes:

 

Module Module1

 

    Sub Main()

        ' 1. Result = Count(N, M) N: mouse win, M: cat win

        ' 2. Result = Count(8, 8)

        Dim number = Count(8, 8)

        Console.WriteLine(number)

        Console.ReadKey()

    End Sub

 

    Public Function Count(ByVal winnerWin As Integer, ByVal winnerFailed As Integer, Optional ByVal currentWin As Integer = 0, Optional ByVal currentFail As Integer = 0) As Integer

        If winnerWin < winnerFailed Then

            Return 0

        End If

 

        If currentWin < currentFail Then

            Return 0

        End If

 

        If currentWin = winnerWin And currentFail = winnerFailed Then

            Return 1

        End If

 

        Dim result As Integer = 0

 

        If currentFail < winnerFailed Then

            result += Count(winnerWin, winnerFailed, currentWin, currentFail + 1)

        End If

 

        If currentWin < winnerWin Then

            result += Count(winnerWin, winnerFailed, currentWin + 1, currentFail)

        End If

 

        Return result

    End Function

 

End Module

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值