Skip to content

Latest commit

 

History

History
31 lines (23 loc) · 742 Bytes

1359_countAllValidPickupAndDeliveryOption.md

File metadata and controls

31 lines (23 loc) · 742 Bytes

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 pickup(i).

Since the answer may be too large, return it modulo 10^9 + 7.

DP Solution

Code

typedef long long ll;
class Solution {
public:
    int countOrders(int n)
    {
        vector<ll> dp(n + 1, 0);
        dp[0] = 1;
        ll mod = pow(10, 9) + 7;

        for (ll i = 1; i <= n; i++) {
            dp[i] = i * dp[i - 1] * (2 * i - 1);
            dp[i] = dp[i] % mod;
        }

        return dp[n];
    }
};