【每日一题】逆序对
逆序对
https://ac.nowcoder.com/acm/problem/14731
Solution
当<>时,其他个位置的取值方案都有种,所以<>会出现在个长度为的01串中;
同理可得<>、<>、...、<>都出现在个长度为的01串中。
所以答案即为。
Code
n, mod = int(input()), int(1e9 + 7) print(0 if n < 2 else (pow(2, n - 2, mod) * (n * (n - 1) // 2 % mod) % mod))