题:https://ac.nowcoder.com/acm/contest/4137/N
分析:注意题意,收益是a[i]*a[i+1],所以分析得,是∑∑a[i]*a[j]
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int M=2200; int a[M]; int main(){ int n; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; ll ans=0; for(int i=1;i<=n;i++){ for(int j=i+1;j<=n;j++) ans+=1ll*a[i]*a[j]; } cout<<ans<<endl; return 0; }