1 条题解
-
0
#include<bits/stdc++.h> #define int long long using namespace std; const int MOD = 1'000'000'000+7; int n; int a[100000+5]; int cnt[5005]; signed main(){ cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; cnt[a[i]]++; } int ans = 0; for(int i=1;i<=5000;i++){ // 2 根长度为 i 的,另外两根长度的和为 i 的 for(int j = 1; j <= i - 1;j++) { int k = i - j; if(j>k) continue; //选一根长度为 j //选一根长度为 k //选两根长度为 i int now = 1; if(j!=k){ now = now * cnt[j] % MOD; now = now * cnt[k] % MOD; } else{ now = now * ((cnt[j] * (cnt[j] - 1) / 2) % MOD) % MOD; } now = now * ((cnt[i] * (cnt[i] - 1) / 2) % MOD) % MOD; ans = (ans + now) % MOD; } } cout<<ans; return 0; }
- 1
信息
- ID
- 4523
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- 3
- 标签
- 递交数
- 11
- 已通过
- 6
- 上传者