파비의 매일매일 공부기록

2023.09.10 Today's Challenge 본문

Problem Solving/LeetCode

2023.09.10 Today's Challenge

fabichoi 2023. 9. 10. 23:45

https://leetcode.com/problems/count-all-valid-pickup-and-delivery-options/

 

Count All Valid Pickup and Delivery Options - LeetCode

Can you solve this real interview question? Count All Valid Pickup and Delivery Options - Given n orders, each order consist in pickup and delivery services.  Count all valid pickup/delivery possible sequences such that delivery(i) is always after of pic

leetcode.com

DP로 푸는 문제.
DP는 언제나 어려운 듯. ㅠ_ㅠ

class Solution:
    def countOrders(self, n: int) -> int:
        MOD = int(1e9 + 7)
        MAX_PAIRS = n + 1
        dp = [0] * MAX_PAIRS
        dp[0] = 1

        for currentPairs in range(1, n + 1):
            dp[currentPairs] = dp[currentPairs - 1] * (2 * currentPairs - 1) * currentPairs % MOD;
        
        return dp[n];
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

2023.09.12 Today's Challenge  (0) 2023.09.12
2023.09.11 Today's Challenge  (0) 2023.09.11
2023.09.09 Today's Challenge  (0) 2023.09.09
2023.09.08 Today's Challenge  (0) 2023.09.08
2023.09.07 Today's Challenge  (0) 2023.09.07
Comments