博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1964 Pipes(插头DP)
阅读量:7063 次
发布时间:2019-06-28

本文共 3825 字,大约阅读时间需要 12 分钟。

Pipes

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 301    Accepted Submission(s): 154

Problem Description
The construction of office buildings has become a very standardized task. Pre-fabricated modules are combined according to the customer’s needs, shipped from a faraway factory, and assembled on the construction site. However, there are still some tasks that require careful planning, one example being the routing of pipes for the heating system.
Amodern office building ismade up of squaremodules, one on each floor being a service module from which (among other things) hot water is pumped out to the other modules through the heating pipes. Each module (including the service module) will have heating pipes connecting it to exactly two of its two to four neighboring modules. Thus, the pipes have to run in a circuit, from the service module, visiting each module exactly once, before finally returning to the service module. Due to different properties of the modules, having pipes connecting a pair of adjacent modules comes at different costs. For example, some modules are separated by thick walls, increasing the cost of laying pipes. Your task is to, given a description of a floor of an office building, decide the cheapest way to route the heating pipes.
 

 

Input
The first line of input contains a single integer, stating the number of floors to handle. Then follow n floor descriptions, each beginning on a new line with two integers, 2 <= r <= 10 and 2 <= c <= 10, defining the size of the floor – r-by-c modules. Beginning on the next line follows a floor description in ASCII format, in total 2r + 1 rows, each with 2c + 2 characters, including the final newline. All floors are perfectly rectangular, and will always have an even number of modules. All interior walls are represented by numeric characters, ’0’ to ’9’, indicating the cost of routing pipes through the wall (see sample input).
 

 

Output
For each test case, output a single line with the cost of the cheapest route.
 

 

Sample Input
3 4 3 ####### # 2 3 # #1#9#1# # 2 3 # #1#7#1# # 5 3 # #1#9#1# # 2 3 # ####### 4 4 ######### # 2 3 3 # #1#9#1#4# # 2 3 6 # #1#7#1#5# # 5 3 1 # #1#9#1#7# # 2 3 0 # ######### 2 2 ##### # 1 # #2#3# # 4 # #####
 

 

Sample Output
28 45 10
 

 

Source
 

 

Recommend
wangye
 
 
插头DP。
插头DP写起来确实很烦,很容易写错,要修改好久。
但是做多了也发现插头DP挺有趣的。
/*HDU 1964 Pipes插头DP每个格子之间的墙壁有一个花费,求用一个环经过每个格子一次的最小花费G++ 46ms*/#include
#include
#include
#include
using namespace std;const int MAXD=15;const int HASH=10007;const int STATE=1000010;struct Node{ int down,right;//每个格子下边和右边墙的花费}node[MAXD][MAXD];int N,M;int maze[MAXD][MAXD];int code[MAXD];int ch[MAXD];//最小表示法使用int ex,ey;//最后一个非障碍格子的坐标struct HASHMAP{ int head[HASH],next[STATE],size; int dp[STATE]; long long state[STATE];//最小表示法,最大是8^11,就是2^33,所以用long long void init() { size=0; memset(head,-1,sizeof(head)); } void push(long long st,int ans) { int i,h=st%HASH; for(i=head[h];i!=-1;i=next[i]) if(state[i]==st) { if(dp[i]>ans)dp[i]=ans; return; } dp[size]=ans; state[size]=st; next[size]=head[h]; head[h]=size++; }}hm[2];void decode(int *code,int m,long long st){ for(int i=m;i>=0;i--) { code[i]=st&7; st>>=3; }}long long encode(int *code,int m){ int cnt=1; memset(ch,-1,sizeof(ch)); ch[0]=0; long long st=0; for(int i=0;i<=m;i++) { if(ch[code[i]]==-1)ch[code[i]]=cnt++; code[i]=ch[code[i]]; st<<=3; st|=code[i]; } return st;}void shift(int *code,int m){ for(int i=m;i>0;i--)code[i]=code[i-1]; code[0]=0;}void dpblank(int i,int j,int cur){ int k,left,up; for(k=0;k

 

转载地址:http://bznll.baihongyu.com/

你可能感兴趣的文章
一个表单对应多个提交按钮,每个提交按钮对应不同的行为
查看>>
tomcat集群时统计session与在线人数
查看>>
Android程序完全退出
查看>>
【Linux】目录权限与文件权限
查看>>
如何将阿拉伯数字每三位一逗号分隔,如:15000000转化为15,000,000
查看>>
select的使用(一)
查看>>
[leetcode]Search a 2D Matrix @ Python
查看>>
java.io.BufferedOutputStream 源码分析
查看>>
Load resources from classpath in Java--reference
查看>>
关于LightMapping和NavMesh烘焙的动态载入
查看>>
(转)Android中使用ormlite实现持久化(一)--HelloOrmLite
查看>>
C语言近程型(near)和远程型(far)的区别是什么?
查看>>
jQuery选择器总结
查看>>
《Continuous Delivery》 Notes 1: The problem of delivering software
查看>>
java android 将小数度数转换为度分秒格式
查看>>
一张图知道HTML5布局(图)
查看>>
LINQ To SQL在N层应用程序中的CUD操作、批量删除、批量更新
查看>>
在网站开发中很有用的8个 jQuery 效果【附源码】
查看>>
桥牌笔记:Skill Level 4 D8
查看>>
[翻译] RSKImageCropper
查看>>