Demon dream fight wooden stick
Thank you @Jackma_mayichao for your help
Topic link: Monster Dream Fighting Wooden Stick
Problem solving ideas
Perceptually understand the meaning of the question: use 4 wooden sticks to form an equilateral triangle . To put it bluntly , choose two equal sticks, and then pick two sticks that add up to the original two sticks, and combine them.
Then we look at combinatorics :
Because mmm is equal to2 2in this question2 , then we can simplify it to get:
n (n − 1) 2 \frac{n(n-1)}{2}2n(n−1)
code
#include<iostream>
#include<cstdio>
#define int long long
using namespace std;
const int mod=1e9+7;
int n,a[5010];
int maxn,ans;
signed main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
int t;
scanf("%lld",&t);
a[t]++;
maxn=max(maxn,t);
}
for(int i=2;i<=maxn;i++)
{
if(a[i]<=1)
continue;
for(int j=1;j<=i/2;j++)
{
if(i-j!=j&&a[i]&&a[j])
ans=(ans+(a[i]*(a[i]-1)/2*a[j]*a[i-j])%mod)%mod;
else if(i-j==j&&a[j]>=1)
ans=(ans+((a[i]*(a[i]-1)/2)%mod*(a[j]*(a[j]-1)/2)%mod)%mod)%mod;
}
}
cout<<ans<<endl;
}