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

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 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.
#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)的更多相关文章
- hdu 4570 Multi-bit Trie 区间DP入门
Multi-bit Trie 题意:将长度为n(n <= 64)的序列分成若干段,每段的数字个数不超过20,且每段的内存定义为段首的值乘以2^(段的长度):问这段序列总的内存最小为多少? 思路: ...
- 【hdu4570】Multi-bit Trie 区间DP
标签: 区间dp hdu4570 http://acm.hdu.edu.cn/showproblem.php?pid=4570 题意:这题题意理解变态的.转自大神博客: 这题题意确实有点难懂,起码对于 ...
- hdu 4597 + uva 10891(一类区间dp)
题目链接:http://vjudge.net/problem/viewProblem.action?id=19461 思路:一类经典的博弈类区间dp,我们令dp[l][r]表示玩家A从区间[l, r] ...
- HDU 2476 String painter (区间DP)
题意:给出两个串a和b,一次只能将一个区间刷一次,问最少几次能让a=b 思路:首先考虑最坏的情况,就是先将一个空白字符串刷成b需要的次数,直接区间DP[i][j]表示i到j的最小次数. 再考虑把a变成 ...
- HDU4570:Multi-bit Trie(区间DP)
Problem Description IP lookup is one of the key functions of routers for packets forwarding and clas ...
- HDU 4597 Play Game(区间DP(记忆化搜索))
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4597 题目大意: 有两行卡片,每个卡片都有各自的权值. 两个人轮流取卡片,每次只能从任一行的左端或右端 ...
- HDU 5151 Sit sit sit 区间DP + 排列组合
Sit sit sit 问题描述 在一个XX大学中有NN张椅子排成一排,椅子上都没有人,每张椅子都有颜色,分别为蓝色或者红色. 接下来依次来了NN个学生,标号依次为1,2,3,...,N. 对于每个学 ...
- hdu 5115 Dire Wolf(区间dp)
Problem Description Dire wolves, also known as Dark wolves, are extraordinarily large and powerful w ...
- HDU 2476 String painter(区间DP)
String painter Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 4745 Two Rabbits(区间DP,最长非连续回文子串)
Two Rabbits Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total ...
随机推荐
- php RSA非对称加密 的实现
基本概念 加密的意义 加密的意义在于数据的传输过程中,即使被第三方获取到传输的数据,第三方也不能获取到数据的具体含义. 加密方式分为对称加密和非对称加密 什么是对称加密? 对称加密只使用一个秘钥,加密 ...
- djjango models表关系
*** detail表级联 student表,detail获取student的学生信息,自己做为扩展 一对一关系 models.OneToOneField student = models.OneTo ...
- AS3中的getChildByName
[转载的...............] 在AS3中,我们可以用getChildByName来获取一个元件,但是要注意返回的类型是DisplayObject,这样一旦我们的元件中有一些自定义的方法就不 ...
- mysql命令行常用指令
一. 启动mysql:service mysql start 停止mysql:service mysql stop 重启mysql:service mysql restart 查看mysql服务状态: ...
- webapi 重复提交问题
https://izen.live/Blog/info/13.html /// <summary> /// action方法过滤器 /// </summary> public ...
- github windows配置以及ssh生成 Permission denied (publickey)
1:进入cmd命令下,或者可以使用GIt工具 (如果出现了 Permission denied 或者配置多个SSH Key跳第6步) git工具 下载地址:https://git-scm.com ...
- 如何在chrome上打开SSL3.0
Chrome默认关闭对SSL3.0的支持,无法访问一些Web应用.可以手动打开他. 启动chrome依次选择 设置->高级->系统->打开代理设置->安全 将使用SSL 3.0 ...
- POST application/json 适用于传递多层的json
本来以为自己写了那么多post请求,ajax已经难不住了呢, 结果现实无比的残酷, 后台换成了java,发多层级的json,后台就取不到了, 虽然到最后还是配置正确了,..记录下来,引以为戒, axi ...
- 单点登录(SSO)原理与案例
单点登录业务流程 概要 详细流程 单点登录系统一共有三个模块,1.服务端 2.客户端 3.代理模块端 用户发送访问客户端的请求,被客户端的代理模块的拦截器拦截,判断cookie中是否含有token(令 ...
- Android开发中同时存在多个ListView的处理
在Android开发过程中,有的时候我们需要在一个页面中通过多个ListView展示不同的数据,让用户直观上感觉是一个ListView在变换着数据. 假设有两个ListView,listView1和L ...