爱奇艺笔试0908第二题动态规划python
# coding=utf-8 if __name__ == "__main__": rb = input().strip().split() r = int(rb[0])+1 b = int(rb[1])+1 rr = max(r, 2) bb = max(b, 3) dp = [bb*[0] for i in range(rr)] for i in range(1, r): dp[i][1] = i / (i+1) dp[i][0] = 1 dp[1][2] = 1/3 for i in range(2, r): dp[i][2] = i/(2+i) + (2/((2+i) * (1+i))) for i in range(1, r): for j in range(3, b): dp[i][j] = i / (i+j) + (j/(i+j)) * ((j-1)/(i+j-1)) * ((i/(i+j-2)) * dp[i-1][j-2] + ((j-2)/(i+j-2))*dp[i][j-3]) print("%.5f" % dp[r-1][b-1])
#爱奇艺##题解##Python#