Test instructions
A school held a non-sincerity, given a sequence of appearances, indicating the value of the cock of n person, if he is the first appearance of the K, his dissatisfaction is (k-1) *diao[i]. In order for everyone's dick to be smaller, the director sets a stack that can be loaded into the stack to change the sequence. That is to say, either follow the given sequence, or put someone in front of some people in the stack, let the person first play, and then let the people in the stack appear, all right. What is the minimum sum of the thread value of a dick?
Ideas:
Want to get down, hey ~
If the range P[1->n] is considered in the order of appearances, only consider P[1] is the first few appearances on the line, assuming that the K, then the interval p[2->k] will have to play first (think about why), and P[k+1->n] after the appearance of P[1]. So, no, two sub-problems? The transfer can be completed as long as the [l,r] is guaranteed that any of its sub-ranges have been considered. After P[j], the entire range of DP values will rise, as their order of appearances becomes k+1~n.
1 //#include <bits/stdc++.h>2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cmath>6#include <map>7#include <algorithm>8#include <vector>9#include <iostream>Ten #definePII pair<int,int> One #defineINF 0x7f3f3f3f A #defineLL Long Long - using namespacestd; - Const DoublePI = ACOs (-1.0); the Const intn= the; - - intD[n], dp[n][n], sum[n], N; - + intcal () - { +Memset (DP,0,sizeof(DP));//Initialize A for(intI=1; i<=n; i++) at for(intj=i+1; j<=n; J + +) -dp[i][j]=INF; - - for(intj=2; j<=n; J + +) - { - for(inti=j-1; I>0; i--) in { - for(intk=0; k<=j-i; k++)//consider letting D[i] be the first k+1 to { + intt= D[i]*k + dp[i+1][I+K] + dp[i+k+1][j]+ (k +1) * (sum[j]-sum[i+K]); -dp[i][j]=min (dp[i][j], t); the } * } $ }Panax Notoginseng returndp[1][n]; - } the + intMain () A { theFreopen ("Input.txt","R", stdin); + intT, case=0;cin>>T; - while(t-- ) $ { $sum[0]=0; -scanf"%d",&n); - for(intI=1; i<=n; i++) the { -scanf"%d",&d[i]);Wuyisum[i]=sum[i-1]+D[i]; the } -printf"Case #%d:%d\n",++Case , Cal ()); Wu } - return 0; About}
AC Code
HDU 4283 You is the one (range DP, classic)