[P1063] Energy necklace

(Given the title copied ugly face directly, here is placed directly linked)

topic:

(I will always remember energy necklace)

Probably thinking:

(I was a mentally retarded)

Each write dp, will repeatedly cross jump in the state transition equation draw the right edge, and then stuck on it. (Nmdwsm)

The same. . . . Today physics may be silly, ruminating on how to obtain dp [i] [k] and dp [k] [j]. . . .

After reading stones merge only their senses. . State before the original listed do not like to consider ah. . . . .

Before the state appears to be a known quantity in the current ah! ! ! ! ! ! !

This will not be stuck in the sand sculpture of this place ah ah ah ah! ! ! ! !

In fact, the idea of ​​solving the problem than the previous release of prisoners should be simple to write a lot, it is the stone merger changed the clothes only. .

On the details of the deal is slightly a little attention. . . Do not copy the array subscript when stored inside. . (Really - the brain is not at home)

Details of the write in comments

Code:

#include<iostream>
#include<cstdio> 
using namespace std;
int a[202],dp[202][202];
int n;
void read(int &x)
{
    char c=0;
    x=0;
    while(!isdigit(c))
    c=getchar();
    while(isdigit(c))
    x=x*10+c-'0',c=getchar();
}
intMaxx;
 int main () 
{ 
    Read (n-); 
    for ( int I = . 1 ; I <= n-; I ++ ) 
    { 
        Read (A [I]); 
        A [I + n-] = A [I]; 
    } 
    for ( int P = 2 ; P <= n-+ . 1 ; P ++) // where at least have two beads can merge 
    {
         for ( int I = . 1 ; p-I + . 1 <= 2 * n-; I ++) // NOTE boundary, the last bead of the first bead on the tail 
        {
             int ends = p-I + . 1;
             For ( int K = I + . 1 ; K <ends; K ++) // not scratch cut 
            dp [i] [ends] = max (dp [i] [ends], dp [i] [k] + dp [k] [ends] + a [I] a * [K] * a [ends]); // two sections are connected to certain 
        } 
    } 
    for ( int I = . 1 ; I <= n-; I ++ ) 
    { 
        Maxx = max (Maxx, DP [I] [I + n-]); // with the combined gravel 
    } 
    COUT << Maxx << endl;
     return  0 ; 
}
Only you can see comments oh. .

Bai Bai

CSP-S RP+++!

Guess you like

Origin www.cnblogs.com/Daz-Os0619/p/11709186.html