题目链接

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.
 
Input
  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
  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
38
 
题意:题目大意,给了一个数列,N个数,要求将数列分成多段,每段长度不能超过20,那么由公式sum( a[i]*2^(l) )  (a[i]表示每一段的第一个数值,l表示这一段的长) 得到一个值,要求输出将数列分割后最小的值。
 
思路:区间DP,定义dp[i]表示从i到数列尾的子数列的值,那么可以得到状态转移方程,dp[i]=min( dp[i] , dp[j]+(1<<(j-i)) ) ( j>i &&j-i<=20)
 
代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
LL a[];
LL dp[]; int main()
{ int T,N;
cin>>T;
while(T--)
{
scanf("%d",&N);
for(int i=;i<=N;i++) scanf("%lld",&a[i]);
for(int i=;i<=N;i++) dp[i]=;
dp[N+]=;
for(int i=N;i>=;i--)
{
for(int j=i+;j-i<=&&j<=N+;j++)
{
dp[i]=min(dp[i],dp[j]+a[i]*(LL)(<<(j-i)));
}
}
printf("%lld\n",dp[]);
}
return ;
}

HDU 4570---Multi-bit Trie(区间DP)的更多相关文章

  1. hdu 4570 Multi-bit Trie 区间DP入门

    Multi-bit Trie 题意:将长度为n(n <= 64)的序列分成若干段,每段的数字个数不超过20,且每段的内存定义为段首的值乘以2^(段的长度):问这段序列总的内存最小为多少? 思路: ...

  2. 【hdu4570】Multi-bit Trie 区间DP

    标签: 区间dp hdu4570 http://acm.hdu.edu.cn/showproblem.php?pid=4570 题意:这题题意理解变态的.转自大神博客: 这题题意确实有点难懂,起码对于 ...

  3. hdu 4597 + uva 10891(一类区间dp)

    题目链接:http://vjudge.net/problem/viewProblem.action?id=19461 思路:一类经典的博弈类区间dp,我们令dp[l][r]表示玩家A从区间[l, r] ...

  4. HDU 2476 String painter (区间DP)

    题意:给出两个串a和b,一次只能将一个区间刷一次,问最少几次能让a=b 思路:首先考虑最坏的情况,就是先将一个空白字符串刷成b需要的次数,直接区间DP[i][j]表示i到j的最小次数. 再考虑把a变成 ...

  5. HDU4570:Multi-bit Trie(区间DP)

    Problem Description IP lookup is one of the key functions of routers for packets forwarding and clas ...

  6. HDU 4597 Play Game(区间DP(记忆化搜索))

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4597 题目大意: 有两行卡片,每个卡片都有各自的权值. 两个人轮流取卡片,每次只能从任一行的左端或右端 ...

  7. HDU 5151 Sit sit sit 区间DP + 排列组合

    Sit sit sit 问题描述 在一个XX大学中有NN张椅子排成一排,椅子上都没有人,每张椅子都有颜色,分别为蓝色或者红色. 接下来依次来了NN个学生,标号依次为1,2,3,...,N. 对于每个学 ...

  8. hdu 5115 Dire Wolf(区间dp)

    Problem Description Dire wolves, also known as Dark wolves, are extraordinarily large and powerful w ...

  9. HDU 2476 String painter(区间DP)

    String painter Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...

  10. HDU 4745 Two Rabbits(区间DP,最长非连续回文子串)

    Two Rabbits Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total ...

随机推荐

  1. mysql学习笔记--数据操作

    一.插入数据 1. 语法:insert into 表名 (字段名.字段名,...) values (值1,值2...) 2. 注意: a. 插入字段的个数和顺序与值的个数和顺序必须一致 b. 通过de ...

  2. adb pull 文件夹到电脑

    正常来讲是支持文件夹的. 但实际执行的时候发现: pull: building file list...0 files pulled. 0 files skipped. 其实出现这个提示,归根到底还是 ...

  3. 未渲染的dom结构,绑定事件,jquery

    使用事件委托 $(document).on('click','selector',function(){ ... }); 示例 $(document).on("click", &q ...

  4. squid代理允许FTP访问设置

    # TAG: acl # Defining an Access List ============================= #Default: # acl all src all # #Re ...

  5. [费用流][NOI2008]志愿者招募

    志愿者招募 题目描述 申奥成功后,布布经过不懈努力,终于成为奥组委下属公司人力资源部门的主管.布布刚上任就遇到了一个难 题:为即将启动的奥运新项目招募一批短期志愿者.经过估算,这个项目需要N 天才能完 ...

  6. [网络流]Farm Tour(费用流

    Farm Tour 题目描述 When FJ's friends visit him on the farm, he likes to show them around. His farm compr ...

  7. SQLite 安装

    Windows 平台安装 下载地址:https://www.sqlite.org/download.html 下载预编译的安装包 将下载的安装包=解压到一个文件夹,有三个重要文件: sqlite3.e ...

  8. 【APP测试(Android)】--安全测试

  9. 20175316盛茂淞 2018-2019-2 《Java程序设计》第3周学习总结

    20175316盛茂淞 2018-2019-2 <Java程序设计>第3周学习总结 教材学习内容总结 1.1.编程语言的几个发展阶段: 面向机器语言 面向过程语言 面向对象语言 2.1.类 ...

  10. linux 查看内网流量

    可以使用iftop进行Linux机器的网络流量监控 安装方法 centos系统下 第一步:安装EPEL源 yum install epel-release 第二部:安装iftop yum instal ...