#include<iostream>
#include<array>
#include<algorithm>
using namespace std;
const int MAX = 1e9 + 7;
int n, maxlen = -1;
array<int, 100005>a;
array<int, 5005>stick;
int main()
{
int ans = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i];
stick[a[i]]++;
maxlen = max(maxlen, a[i]);
}
for (int i = 0; i <= maxlen; i++)
for (int j = i; j <= maxlen; j++)
if (i + j > 5000)
break;
else if (i != j)
ans = (ans + stick[i + j] * (stick[i + j] - 1) / 2 * stick[i] * stick[j]) % MAX;
else
ans = (ans + stick[i + j] * (stick[i + j] - 1) / 2 * stick[i] * (stick[i] - 1) / 2) % MAX;
cout << ans;
return 0;
}
洛谷P3799 妖梦拼木棒进阶解法
最新推荐文章于 2024-09-22 11:58:18 发布
本文展示了一个使用C++编写的程序,该程序通过输入一组整数并统计可能的组合数量来解决特定问题。程序利用了标准库中的数组和算法功能,并通过优化循环避免不必要的计算。
468

被折叠的 条评论
为什么被折叠?



