noip2006T1 能量项链

     最近一直在做noip的题,由于太水一直没有写题解,可是这道题,这道题。啊啊啊啊……

     明明水的要命,调了一节课啊!!我干脆不要搞OI了啊!

     特别逗比的错误啊!!!!

     代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#define N 251
using namespace std;

int n;
int a[N][N];
int val[N];

int main()
{
    scanf("%d", &n);
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; ++i)
    {
        int x; scanf("%d", &x);
        val[i] = val[i+n] = x;
    }
    
    for (int j = 1; j < n; ++j)
        for (int i = 1; i <= 2*n, i+j <= 2*n; ++i) // i  一定要到 2*n !!!!!
            for (int k = i; k < i+j; ++k)
                a[i][i+j] = max(a[i][i+j], a[i][k] + a[k+1][i+j] + val[i]*val[k+1]*val[i+j+1]);
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        ans = max(ans, a[i][i+n-1]);
    printf("%d\n", ans);
    return 0;
}

 

posted @ 2014-09-15 20:22  handsomeJian  阅读(208)  评论(0编辑  收藏  举报