HDU 4570 Multi-bit Trie(区间dp)

原创 2015年07月10日 10:09:50

Multi-bit Trie

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 539    Accepted Submission(s): 214

Problem Description
  IP lookup is one of the key functions of routers for packets forwarding and classifying. Generally, IP lookup can be simplified as a Longest Prefix Matching (LPM) problem. That's to find the longest prefix in the Forwarding Information Base (FIB) that matches the input packet's destination address, and then output the corresponding Next Hop information.

  Trie-based solution is the most wildly used one to solve LPM. As shown in Fig.1(b), an uni-bit trie is just a binary tree. Processing LPM on it needs only traversing it from the root to some leaf, according to the input packet's destination address. The longest prefix along this traversing path is the matched one. In order to reduce the memory accesses for one lookup, we can compress some consecutively levels of the Uni-bit Trie into one level, transforming the Uni-bit Trie into a Multi-bit Trie.
  For example, suppose the strides array is {3, 2, 1, 1}, then we can transform the Uni-bit Trie shown in Fig.1(b) into a Multi-bit Trie as shown in Fig.1(c). During the transforming process, some prefixes must be expanded. Such as 11(P2), since the first stride is 3, it should be expanded to 110(P2) and 111(P2). But 110(P5) is already exist in the FIB, so we only store the longer one 110(P5).
  Multi-bit Trie can obviously reduce the tree level, but the problem is how to build a Multi-bit Trie with the minimal memory consumption (the number of memory units). As shown in Fig.1, the Uni-bit Trie has 23 nodes and consumes 46 memory units in total, while the Multi-bit Trie has 12 nodes and consumes 38 memory units in total.

  The first line is an integer T, which is the number of testing cases.
  The first line of each case contains one integer L, which means the number of levels in the Uni-bit Trie.
  Following L lines indicate the nodes in each level of the Uni-bit Trie.
  Since only 64 bits of an IPv6 address is used for forwarding, a Uni-bit Trie has maximal 64 levels. Moreover, we suppose that the stride for each level of a Multi-bit Trie must be less than or equal to 20.

  Output the minimal possible memory units consumed by the corresponding Multi-bit Trie.

Sample Input
1 7 1 2 4 4 5 4 3

Sample Output




比如:n=7,A={1 2 4 4 5 4 3},将其分成1 2 4| 4 5| 4| 3,
而如果分成1 2| 4 4 5| 4 3,则其所用空间为1*2^2+4*2^3+4*2^2=52,比38大。




#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define bug printf("hihi\n")

#define eps 1e-8
typedef __int64 ll;

using namespace std;

#define INF 0x3f3f3f3f
#define N 65

ll dp[N];
ll a[N];
int n;
int main()
    int i,j,t;


    return 0;


Hdu 4570 Multi-bit Trie(区间dp)

点击打开链接 Multi-bit Trie Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav...
  • madaidao
  • madaidao
  • 2014年10月26日 15:17
  • 259

HDU 4570 - Multi-bit Trie(区间DP)

题目: http://acm.hdu.edu.cn/showproblem.php?pid=4570 题意: 题目。。。因为题目太烦比赛的没有看。 直接解释样例:A={1 2 4 4 5 ...
  • u013534690
  • u013534690
  • 2015年05月13日 13:11
  • 314

HDU 4570 Multi-bit Trie (区间DP)

Multi-bit TrieTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T...
  • mrlry
  • mrlry
  • 2016年08月30日 18:53
  • 103

hdu 4570 Multi-bit Trie 【区间dp】

点击打开链接 题意难度太高,后来问llm说大致是 给你n个数,然后让你随意划分成任意段区间(每一段最长为20),保证最后的区间和最小, 每一段区间值的算法是这样的,该区间值等于区间首字...
  • zoro_n
  • zoro_n
  • 2017年07月10日 10:35
  • 55

hdu 4570 Multi-bit Trie (区间DP)

Problem Description   IP lookup is one of the key functions of routers for packets forwarding and c...
  • hndu__lz
  • hndu__lz
  • 2016年08月09日 18:00
  • 83

HDU 4570 Multi-bit Trie(区间DP)

题意:这题题意确实有点难懂,起码对于我这个英语渣渣来说是这样,于是去别人的博客看了下题目意思,归纳起来如下: 给出一个长度为n的数列,将其分成若干段,要求最小,其中ai是每一段数列的第一项,bi...
  • clx55555
  • clx55555
  • 2016年11月15日 12:19
  • 120

hdu 4570 Multi-bit Trie

原文链接 。。。这一题,,,花时间最多的是看题目。题意(别处复制): 一个长度为n的数列,将其分成若干段(每一段的长度要...
  • carryheart
  • carryheart
  • 2016年08月03日 19:56
  • 324

HDU 4570 Multi-bit Trie 解题报告

题目 比赛 题意:这道题最难的就是题意了            我们根据样例YY出来简化的题意:给出一个长度为n的数列,将其分成若干段,要求最小,其中ai是每一段数列的第一项,bi是每一段的长度,l为...
  • u010638776
  • u010638776
  • 2013年07月06日 12:06
  • 1063

HDU - 4570 Multi-bit Trie 2013长沙邀请赛

题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4570 题意:题目花了一个乱糟糟的图,然后给了一对乱糟糟的文字,然后抽象出数学模型就是这样的...
  • canghai_wangzi
  • canghai_wangzi
  • 2017年05月30日 16:32
  • 99

HDU4570:Multi-bit Trie(区间DP)

Problem Description   IP lookup is one of the key functions of routers for packets forwarding and cl...
  • libin56842
  • libin56842
  • 2013年08月01日 15:20
  • 2169
您举报文章:HDU 4570 Multi-bit Trie(区间dp)