现在的位置: 首页 > 综合 > 正文

foj2015 Vote

2018年04月23日 ⁄ 综合 ⁄ 共 2522字 ⁄ 字号 评论关闭

Problem 2015 Vote

Accept: 34    Submit: 132


Time Limit: 1000 mSec    Memory Limit : 32768 KB


 Problem Description

Here are n Candidates in one election. Every Candidate could vote any one (of course himself/herself). In this election, the one who gets more than half of n become the winner! However, sometimes no winner could be determined (No one gets more than half of n votes)!

Now you are given the number of Candidates and the final winner m, here if m is equal to -1, then it means that no one wins, otherwise m is the index of the Candidate. (The index of Candidates is 0, 1, 2, … n – 1 respectively) Abcdxyzk wants to know the number of possible ways of the final result if the winner if m. (m = -1 for no winner of course) However, the answer maybe large, so abcdxyzk just want the remainder of the answer after divided by 1000000007.


 Input

There are several test cases.

For each case, only two integers n and m in a single line indicates n Candidates and the final winner m. (1 <= n <= 100, -1 <= m < n)


 Output

For each test case, output the number of possible ways of the final election!


 Sample Input

2 1 

3 -1 

4 1


 Sample Output

4


 Hint

In case 1, only one possible ways of the final result because both 0 and 1 vote to 1.

In case 2, only one possible ways of the final result because all of 0, 1, and 2 get one vote.

In case 3, there are 4 possible ways of final result:

(1) 0: 1 (vote(s)) 1: 3 (vote(s)) 2: 0 (vote(s)) 3: 0 (vote(s))

(2) 0: 0 (vote(s)) 1: 3 (vote(s)) 2: 1 (vote(s)) 3: 0 (vote(s))

(3) 0: 0 (vote(s)) 1: 3 (vote(s)) 2: 0 (vote(s)) 3: 1 (vote(s))

(4) 0: 0 (vote(s)) 1: 4 (vote(s)) 2: 0 (vote(s)) 3: 0 (vote(s))


 Source

FOJ有奖月赛
-2011

03

 

这题和无语校赛热身赛出的台球题有那么点神似,当然比那题难很多……

对于每个人,获胜的方法数都是一样的……

先求出
dp[n][m],表示
m
个人分
n
张投票的方法数。

如果有人获胜,显然先枚举他获得的票数,剩下的票数让m-1
个人分,所以显然就是
dp[t][m-1]
,其中
t
就是枚举的剩下的票数。

如果没人获胜,那么就是n
个人分
n
张票,然后减去有人当选的方法数,前面说了,每个人获胜的方法数是一样的,所以只需要减去前面算出有人获胜的方法数乘上
n
个人的结果。

dp[n][n]-ans*n
,其中
ans
就是有某一个人获胜的方法数。

代码:


【上篇】
【下篇】

抱歉!评论已关闭.