Description

在2xyz年,人类已经移民到了火星上。由于工业的需要,人们开始在火星上采矿。火星的矿区是一个边长为N的正六边形,为了方便规划,整个矿区被分为6*N*N个正三角形的区域(如图1)。

 

 

整个矿区中存在A矿,B矿,C矿三个矿场,和a厂,b厂,c厂三个炼矿厂。每个三角形的区域可以是一个矿场、炼矿厂、山地、或者平地。现在矿区管理局要求建立一个交通系统,使得矿场和对应炼矿厂之间存在一条公路,并且三条公路互不交叉(即一个三角形区域中不存在两条以上运输不同矿的公路)。两个三角形区域是相邻的当且仅当这两个三角形存在公共边,只有相邻的两个区域之间才能建一段路,建这段路的费用为1。注意,山地上是不能建公路的。由于火星金融危机的影响,矿区管理局想知道建立这样一个交通系统最少要花多少费用。更多的,当局向知道有多少种花费最小的方案。

Input

第1行一个整数N。表示这个矿区是边长为N的正六边形。

接下来有6*N*N的整数,分为2*N行,表示矿区当前区域的情况。0表示平地,1,2,3表示对应的矿区或者炼矿厂,4表示山地。(样例1对应图2)。可能有多组数据,请处理到文件结尾

Output

对于每组数据,包含两个整数,表示最小费用和达到最小费用的方案数。如果找不到符合要求的方案,输出-1 -1。由于方案数可能过大,所以请把方案数mod 1000000007

Sample Input

【样例输入1】

2


0 1 0 0 0


0 0 2 0 4 0 0


0 0 4 3 0 3 2


0 0 0 1 0


【样例输入2】


3


0 0 0 1 0 0 0


0 0 0 0 0 0 0 0 0


0 0 2 0 0 0 0 0 0 0 0


0 0 0 0 0 0 3 0 0 0 0


0 0 0 0 0 0 0 0 0


0 3 0 1 0 2 0

Sample Output

【样例输出1】

18 1


【样例输出2】


44 1

HINT

对于100%的数据,N≤6

 
 
恩恩。。什么插头dp ,看不懂,还不是具体做法up to具体题目啊。。。。
所以只好自己瞎YY了一个dp,练习了一下带hash的spfa版dp。。
具体就是两个三角形构成的平行四边形作为一个格子,预处理每个格子可以接受从左方和上方连过来的路径
以及与其相对应的连向右方和下方的 路径, 这也许就是插头吧,因为只有1,2,3或0(即没有路径连来)四种插头,
用四进制状压已宽搜出的状态之后 就可以一格一格的dp了。嘛 细节题
 
 const ss=;
const mo=;
const nn=;
var
b:array[..,..]of longint;
a:array[..,..,..,..,..,..]of boolean;
ax:array[..,..,..,..,..,..]of longint;
d:array[..nn]of longint;
g:array[..ss,..]of longint;
next,u:array[..nn,..]of longint;
f,w:array[..nn,..]of longint;
e:array[..nn,..]of boolean;
l,r,kk,qq,sx,sy,ii,jj,t1,t2,tt,i,j,n,m,k,t,x,y,z,p,q:longint;
procedure o(p,k,q,t:longint);
begin
ax[i,j,p,q,k,t]:=;
if (b[i+,j]<>)and(k<>b[i+,j])and(k<>) then exit;
if (b[i,j+]<>)and(t<>b[i,j+])and(t<>) then exit;
a[i,j,p,q,k,t]:=true;
if (p+k>)or((x>)and(x<)) then inc(ax[i,j,p,q,k,t]);
if (q+t>)or((y>)and(y<)) then inc(ax[i,j,p,q,k,t]);
end;
function hash(x,t:longint):longint;
var i:longint;
begin
if t=tt then
begin
i:=x mod ss+;
if u[g[i,t],t]=x then begin hash:=g[i,t]; g[i,t]:=next[g[i,t],t]; exit; end;
i:=g[i,t];
while u[next[i,t],t]<>x do i:=next[i,t];
hash:=next[i,t];
next[i,t]:=next[next[i,t],t]; exit;
end;
i:=g[x mod ss+,t];
while (i<>)and(u[i,t]<>x) do i:=next[i,t];
if u[i,t]=x then exit(i);
inc(t2); i:=x mod ss+; u[t2,t]:=x;
next[t2,t]:=g[i,t]; g[i,t]:=t2; exit(t2);
end;
begin
while true do
begin
fillchar(a,sizeof(a),);
fillchar(b,sizeof(b),);
fillchar(ax,sizeof(ax),);
readln(n); if eof then exit;
x:=n*+; m:=n*;
u[,]:=-; u[,]:=-;
for i:= to n+n+ do
for j:= to m+ do b[i,j]:=;
for i:= to n do
begin
for j:= to x do read(b[i,j]);
x:=x+;
end;
for i:=n+ to n+n do
begin
x:=x-;
for j:=m-x+ to m do read(b[i,j]);
end; n:=n*; readln;
for i:= to n do
for j:= to m do
if j and = then
begin
x:=b[i,j-]; y:=b[i,j];
if (x=)and(y=) then
begin
for p:= to do begin o(,,p,p); o(,p,p,); o(,p,,p); o(p,,,p); o(p,,p,); o(p,p,,); end;
for p:= to do for q:= to do o(p,p,q,q);
end else
if (x=)and(y<>) then
begin
for p:= to do begin o(p,p,y,); o(p,p,,y); end;
o(y,,,); o(,y,,);
end else
if (x=)and(y=) then
begin
for p:= to do o(p,p,,);
end else
if (x<>)and(y=) then
begin
for p:= to do begin o(x,,p,p); o(,x,p,p); end;
o(,,x,); o(,,,x);
end else
if (x<>)and(y<>) then
begin
o(x,,y,); o(x,,,y); o(,x,y,); o(,x,,y);
if x=y then o(,,,);
end else
if (x<>)and(y=) then
begin
o(x,,,); o(,x,,);
end else
if (x=)and(y=) then
begin
for p:= to do o(,,p,p);
end else
if (x=)and(y<>) then
begin
o(,,y,); o(,,,y);
end else o(,,,);
end;
for i:= to nn do
for j:= to do f[i,j]:=nn;
tt:=; i:=hash(,); tt:=;
f[i,]:=; w[i,]:=; e[i,]:=true;
l:=; r:=; t:=; p:=; q:=; kk:=; t1:=; t2:=;
while true do
begin
while true do
begin
k:=hash(d[l],tt);
if q= then d[l]:=d[l]*;
x:=(d[l]>>(q-))and ;
y:=(d[l]>>q)and ;
sx:=d[l]-x<<(q-)-y<<q;
for ii:= to do
for jj:= to do
if a[p,q,x,y,ii,jj] then
begin
qq:=sx+ii<<(q-)+jj<<q;
z:=hash(qq,kk);
if f[z,kk]>f[k,tt]+ax[p,q,x,y,ii,jj] then
begin
f[z,kk]:=f[k,tt]+ax[p,q,x,y,ii,jj];
w[z,kk]:=w[k,tt];
if not e[z,kk] then
begin
e[z,kk]:=true; d[t]:=qq; inc(t);
if t=nn then t:=;
end;
end else
if f[z,kk]=f[k,tt]+ax[p,q,x,y,ii,jj] then
begin
inc(w[z,kk],w[k,tt]);
if w[z,kk]>=mo then dec(w[z,kk],mo);
end;
end;
e[k,tt]:=false; w[k,tt]:=;
f[k,tt]:=nn;
if l=r then break;
inc(l); if l=nn then l:=;
end;
inc(l); if l=nn then l:=;
if l=t then break;
if t= then r:=nn- else r:=t-; tt:=kk; kk:=-kk; t1:=t2; t2:=;
if q=m then begin q:=; inc(p); end else inc(q,);
if p>n then break;
end;
i:=g[,tt];
while (i<>)and(u[i,tt]<>) do i:=next[i,tt];
if i= then writeln('-1 -1') else
begin
writeln(f[i,tt]-,' ',w[i,tt]);
end;
while l<>t do
begin
k:=hash(d[l],tt);
e[k,tt]:=false; w[k,tt]:=;
f[k,tt]:=nn;
if l=r then break;
inc(l); if l=nn then l:=;
end;
end;
end.

Caster

 

BZOJ2283: [Sdoi2011]火星移民的更多相关文章

  1. [Sdoi2011]火星移民

    2283: [Sdoi2011]火星移民 Time Limit: 40 Sec  Memory Limit: 512 MBSubmit: 119  Solved: 56[Submit][Status] ...

  2. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  3. BZOJ 2243: [SDOI2011]染色 [树链剖分]

    2243: [SDOI2011]染色 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 6651  Solved: 2432[Submit][Status ...

  4. bzoj-2243 2243: [SDOI2011]染色(树链剖分)

    题目链接: 2243: [SDOI2011]染色 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 6267  Solved: 2291 Descript ...

  5. 【BZOJ2243】[SDOI2011]染色 树链剖分+线段树

    [BZOJ2243][SDOI2011]染色 Description 给定一棵有n个节点的无根树和m个操作,操作有2类: 1.将节点a到节点b路径上所有点都染成颜色c: 2.询问节点a到节点b路径上的 ...

  6. BZOJ 2286: [Sdoi2011]消耗战

    2286: [Sdoi2011消耗战 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 2082  Solved: 736[Submit][Status] ...

  7. bzoj 2242: [SDOI2011]计算器 BSGS+快速幂+扩展欧几里德

    2242: [SDOI2011]计算器 Time Limit: 10 Sec  Memory Limit: 512 MB[Submit][Status][Discuss] Description 你被 ...

  8. 【BZOJ】【2245】【SDOI2011】工作安排

    网络流/费用流 裸题吧……直接建模就好了……所谓的“分段函数”就是吓唬你的,其实就是对于每个人分开建几条流量不同.费用不同的弧而已. 对每种产品,连S->i ,(c[i],0):对每个工作人员 ...

  9. bzoj2243:[SDOI2011]染色

    链剖就可以了.一开始的想法错了.但也非常接近了.妈呀调的要死...然后把字体再缩小一号查错起来比较容易QAQ. #include<cstdio> #include<cstring&g ...

随机推荐

  1. 0元免费领《JAVA日志》教程,天啦噜!

    天啦,老码疯了!辛辛苦苦,费心费力准备的<java日志实战及解析>教程真的不要钱了吗? 作为添物网的小编,每天看着老码为了给大家录制课程,加班加点的做课件,为了保证课程的质量,老码一遍又一 ...

  2. linux centos7 swap 设置 添加 删除

    操作  需要  root 用户 权限 dd 命令 创建swap用的分区文件 /var/swap  dd if=/dev/zero of=/var/swap bs=1024 count=2048000 ...

  3. [Vijos1512] SuperBrother打鼹鼠 (二维树状数组)

    传送门 直接搞就行. 注意下表re从零开始,而树状数组搞不了0,所以统一增加一个偏移量1. (话说数据随机是什么鬼?) # include <iostream> # include < ...

  4. CF671D:Roads in Yusland

    n<=300000个点的树,给m<=300000条带权路径(ui,vi,保证vi是ui的祖先)求覆盖整棵树每条边的最小权和. 好题好姿势!直观的看到可以树形DP,f[i]表示把点i包括它爸 ...

  5. maven 编译出错 Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean

    eclipse在使用maven的tomcat控件编译java程序时,报错 Failed to execute goal org.apache.maven.plugins:maven-clean-plu ...

  6. Method, apparatus and system for acquiring a global promotion facility utilizing a data-less transaction

    A data processing system includes a global promotion facility and a plurality of processors coupled ...

  7. 并发编程——IO模型

    前言 同步(synchronous):一个进程在执行某个任务时,另外一个进程必须等待其执行完毕,才能继续执行 #所谓同步,就是在发出一个功能调用时,在没有得到结果之前,该调用就不会返回.按照这个定义, ...

  8. 洛谷——P2916 [USACO08NOV]为母牛欢呼Cheering up the Cows

    https://www.luogu.org/problem/show?pid=2916 题目描述 Farmer John has grown so lazy that he no longer wan ...

  9. Spring Data Redis与Jedis的选择(转)

    说明:内容可能有点旧,需要在业务上做权衡. Redis的客户端有两种实现方式,一是可以直接调用Jedis来实现,二是可以使用Spring Data Redis,通过Spring的封装来调用.应该使用哪 ...

  10. 【转】 一张图看懂开源许可协议,开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别

    原文:http://blog.csdn.net/testcs_dn/article/details/38496107 ----------------------------------------- ...