原题链接 https://www.luogu.com.cn/problem/P3799
题目描述
从 n 根木棒中选 4 根,用其中两根拼成一条边,另外两根各作一边,组成等边三角形。求不同的选法数。
输入 第一行是木棒数 n,随后 n 行各给出一根木棒的长度。
输出 输出选法数对 1000000007 取模的结果。
输入输出样例
输入
4
1
1
2
2输出
1题解
from operator import mul
n, *g = map(int, open(0).read().split())
cnt = [0] * 5001
for x in g:
cnt[x] += 1
ans = 0
for s in range(2, 5001):
if cnt[s] < 2:
continue
mid, h = s // 2, (s - 1) // 2
res = sum(map(mul, cnt[:h+1], cnt[s:s-h-1:-1]))
if s % 2 == 0:
res += cnt[mid] * (cnt[mid] - 1) // 2
ans += cnt[s] * (cnt[s] - 1) // 2 * res
print(ans % (10**9 + 7))