合并石子(非dp版)

题: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;
}
View Code

 

posted @ 2020-02-01 20:27  starve_to_death  阅读(82)  评论(0编辑  收藏  举报