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 ...
 
随机推荐
- Pandas合并数据集之merge、join方法
			
合并数据集 pandas.merge 可根据一个或多个键将不同DataFrame中的行连接起来. pandas.concat 可以沿着一条轴将多个对象堆叠到一起. combine_first merg ...
 - android studio 创建图标
			
参考 https://www.cnblogs.com/c546170667/p/5975550.html File-New-Image Asset
 - 关于EL表达式随笔记录
			
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
 - 算法练习LeetCode初级算法之树
			
二叉树的前序遍历 我的解法:利用递归,自底向下逐步添加到list,返回最终的前序遍历list class Solution { public List<Integer> preorderT ...
 - centos 7 安装redis 3.2.1
			
https://www.cnblogs.com/zuidongfeng/p/8032505.html 下载安装包: http://download.redis.io/releases/ 根据需要自己选 ...
 - win10系统配置jdk环境不能用%JAVA_HOME% 代替目录
			
发现以前配好的java环境变量和tomcat环境变量全都清空了,在重新配置的时候总是出现问题,即在cmd命令窗口下,输入java,显示正常,输入java -version 也是显示正常,唯独输入jav ...
 - 谷歌开源的一个BTREE实现 Go语言
			
// Copyright 2014 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "Licens ...
 - Python 多进程编程之 进程间的通信(在Pool中Queue)
			
Python 多进程编程之 进程间的通信(在Pool中Queue) 1,在进程池中进程间的通信,原理与普通进程之间一样,只是引用的方法不同,python对进程池通信有专用的方法 在Manager()中 ...
 - POJ 1328 Radar Installation 贪心 A
			
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
 - OpenCV图像分割1
			
1.基于阈值 1.1原理 灰度阈值化,假设输入图像为f,输出图像为g,则阈值化公式如下: g(i,j)=1 当f(i,j)>=T g(i,j)=0 当f(i,j)<T 1.2适用范围 当 ...