pku 2288 Islands and Bridges(状态压缩DP)
来源:互联网 发布:机器人模拟软件 编辑:程序博客网 时间:2024/06/11 12:06
Description
Given a map of islands and bridges that connect these islands, a Hamilton path, as we all know, is a path along the bridges such that it visits each island exactly once. On our map, there is also a positive integer value associated with each island. We call a Hamilton path the best triangular Hamilton path if it maximizes the value described below.
Suppose there are n islands. The value of a Hamilton path C1C2...Cn is calculated as the sum of three parts. Let Vi be the value for the island Ci. As the first part, we sum over all the Vi values for each island in the path. For the second part, for each edge CiCi+1 in the path, we add the product Vi*Vi+1 . And for the third part, whenever three consecutive islands CiCi+1 Ci+2 in the path forms a triangle in the map, i.e. there is a bridge between Ci and Ci+2 , we add the product Vi*Vi+1 *Vi+2 .
Most likely but not necessarily, the best triangular Hamilton path you are going to find contains many triangles. It is quite possible that there might be more than one best triangular Hamilton paths; your second task is to find the number of such paths.
[state][i][j],state表示已经到达过的顶点,i记录倒数第2个顶点,j记录倒数第一个顶点。
DP[][][]记录最大值,way[][][]记录最大值对应的路径数。
做这题,才注意到位运算的<<>>左移右移优先级好低,不如+-加减,得加括号。
要注意的地方有两个
1.一个点的情况
2.用__int64
我的代码用的是最直观的DP,跑了2500ms。
假设state1可以由state2转化得到,通过分析可以发现0<=state2<state1。于是可以在最外层循环用state递增。
用记忆化搜索重新写了一遍。本以为可以很快搞定,但WA了差不多10次。__int64,血的教训。
- pku 2288 Islands and Bridges(状态压缩DP)
- poj2288 Islands and Bridges 状态压缩dp
- poj 2288 Islands and Bridges解题报告-状态压缩dp
- POJ 2288 Islands and Bridges 状态压缩DP
- POJ-2288 Islands and Bridges 状态压缩DP TSP
- poj 2288 状态压缩dp Islands and Bridges
- 【汉密尔顿、DP|状态压缩】POJ-2288 Islands and Bridges
- POJ 2288 Islands and Bridges 状态压缩DP
- POJ 2288 Islands and Bridges(状态压缩)
- Poj 2288 Islands and Bridges 状态压缩
- (中等) 状态压缩dp HOJ 1894 Islands and Bridges
- poj 2288 Islands and Bridges 状态压缩dp(附详细注释)
- POJ2288:Islands and Bridges(状态压缩)
- 状态压缩DP——poj2288 Islands and Bridges 又见旅行商问题
- Islands and Bridges - POJ 2288 状压dp
- 状压DP poj 2288 Islands and Bridges
- poj 2288 Islands and Bridges(状压dp)
- poj 2288 Islands and Bridges(状压dp)
- java的instanceof自己的一点总结
- VC2008下配置boost库使用正则表达式
- 多线程学习笔记
- 爱上一个人的感觉
- 传智博客 9月10日团报的请进
- pku 2288 Islands and Bridges(状态压缩DP)
- asp.net动态编辑母版页(与母版页通信,如修改控件属性等)
- 通过租用ISP的帧中继交换网络,连接四个网络
- 成功离我有多远
- 人的一生终将要错过一些人
- 人生的坐标该如何画上句点
- MTK 项目在new的时候老是报plmncreate.exe错误的解决办法
- 第五章实验四第三题
- 网络字节序与主机字节序