输出包括一行四个正整数N(2<=N<=5000)、M(1<=M<=N)、K(1<=K<=5000)、P(1<=P<=N)。
输出一个整数,代表最终走到P的方法数对取模后的值。
5 2 3 3
3
1).2->1,1->2,2->3
2).2->3,3->2,2->3
3).2->3,3->4,4->3
1000 1 1000 1
591137401
注意答案要取模
时间复杂度,空间复杂度。
n,m,k,p = map(int,input().split()) if n < 2&nbs***bsp;k < 1&nbs***bsp;m < 1&nbs***bsp;m > n&nbs***bsp;p < 1&nbs***bsp;p > n: print(0) dp = [0] * (n+1) dp[p-1] = 1 for i in range(k): leftup = dp[0] for j in range(n): temp = dp[j] if j == 0: dp[j] = dp[j+1]%100000007 elif j == n-1: dp[j] = leftup%100000007 else: dp[j] = (leftup + dp[j+1])%100000007 leftup = temp print(dp[m-1])