Dp hdu-4570-Multi-bit Trie

Source: Internet
Author: User

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>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.