Question meaning:
The meaning of the conversion is to give n numbers, and find a Division so that the first number of each segment is multiplied by the sum of the power and the minimum number of the segment 2. The number of each segment cannot exceed 20.
Solution:
Dp [I] indicates the minimum sum of the partitions that meet the question requirements when I count.
Dp [I] = Min (dp [I], sa [I-j + 1] * bi [j] + dp [I-j]);
Code:
<SPAN style = "FONT-SIZE: 14px "> # include <iostream> # include <cmath> # include <cstdio> # include <cstdlib> # include <string> # include <cstring> # include <algorithm> # include <vector> # include <map> # include <set> # include <stack> # include <list> # include <queue> # define eps 1e-6 # define INF 0x1f1f1f1f # define PI acos (-1.0) # define ll _ int64 # define lson l, m, (rt <1) # define rson m + 1, r, (rt <1) | 1 // # pragma comment (linker, "/stacks: 1024 1000000,1024000000 ") using namespace std;/* freopen (" data. in "," r ", stdin); freopen (" data. out "," w ", stdout); */# define Maxn 70ll dp [Maxn], sa [Maxn]; int n; int bi [25]; ll Min (ll a, ll B) {return a <B? A: B;} int main () {int t; bi [0] = 1; for (int I = 1; I <= 20; I ++) bi [I] = bi [I-1] * 2; scanf ("% d", & t); while (t --) {scanf ("% d", & n ); for (int I = 1; I <= n; I ++) scanf ("% I64d", & sa [I]); memset (dp, INF, sizeof (dp); dp [0] = 0; for (int I = 1; I <= n; I ++) {/* if (I <= 20) dp [I] = sa [1] * bi [I]; * // enumerate the length of the last segment for (int j = 1; j <= 20 & I> = j; j ++) // no more than 20, {dp [I] = Min (dp [I], sa [I-j + 1] * bi [j] + dp [I-j]);} printf ("% I64d \ n", dp [n]);} return 0 ;}</SPAN>