博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ural 1519 Formula 1 (插头DP)
阅读量:6701 次
发布时间:2019-06-25

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

1519. Formula 1

Time Limit: 1.0 second
Memory Limit: 16 MB

Background

Regardless of the fact, that Vologda could not get rights to hold the Winter Olympic games of 20**, it is well-known, that the city will conduct one of the Formula 1 events. Surely, for such an important thing a new race circuit should be built as well as hotels, restaurants, international airport - everything for Formula 1 fans, who will flood the city soon. But when all the hotels and a half of the restaurants were built, it appeared, that at the site for the future circuit a lot of gophers lived in their holes. Since we like animals very much, ecologists will never allow to build the race circuit over the holes. So now the mayor is sitting sadly in his office and looking at the map of the circuit with all the holes plotted on it.

Problem

Who will be smart enough to draw a plan of the circuit and keep the city from inevitable disgrace? Of course, only true professionals - battle-hardened programmers from the first team of local technical university!.. But our heroes were not looking for easy life and set much more difficult problem: "Certainly, our mayor will be glad, if we find how many ways of building the circuit are there!" - they said.
It should be said, that the circuit in Vologda is going to be rather simple. It will be a rectangle
N*
M cells in size with a single circuit segment built through each cell. Each segment should be parallel to one of rectangle's sides, so only right-angled bends may be on the circuit. At the picture below two samples are given for
N =
M = 4 (gray squares mean gopher holes, and the bold black line means the race circuit). There are no other ways to build the circuit here.
Problem illustration

Input

The first line contains the integer numbers
N and
M (2 ≤
N,
M ≤ 12). Each of the next
N lines contains
M characters, which are the corresponding cells of the rectangle. Character "." (full stop) means a cell, where a segment of the race circuit should be built, and character "*" (asterisk) - a cell, where a gopher hole is located.

Output

You should output the desired number of ways. It is guaranteed, that it does not exceed 2
63-1.

Samples

input output
4 4**..............
2
4 4................
6

 

 

具体看cdq的论文:

 

插头DP入门题:

/*最小表示法*/#include
#include
#include
#include
using namespace std;const int MAXD=15;const int HASH=30007;const int STATE=1000010;using namespace std;int N,M;int maze[MAXD][MAXD];int code[MAXD];int ch[MAXD];//最小表示法使用int ex,ey;//最后一个非障碍格子的坐标struct HASHMAP{ int head[HASH],next[STATE],size; long long state[STATE]; long long f[STATE]; void init() { size=0; memset(head,-1,sizeof(head)); } void push(long long st,long long ans) { int i; int h=st%HASH; for(i=head[h];i!=-1;i=next[i])//这里要注意是next if(state[i]==st) { f[i]+=ans; return; } state[size]=st; f[size]=ans; 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://mfgoo.baihongyu.com/

你可能感兴趣的文章
ubuntu 12.04 nginx+ mono-fastcgi-server
查看>>
CloudStack 实现VM高可用特性
查看>>
6425C-Lab8 使用组策略管理安全性(1)
查看>>
Dense Mode & Sparse mode(密模式与疏模式)
查看>>
【点评】运维工程师的职责和前景 【第一次编辑】
查看>>
smarty配置以及变量调节器详解
查看>>
rman备份恢复命令之switch
查看>>
技术合作 索尼腾龙联手申请镜头专利
查看>>
关于 MySQL 8.0 新特性“隐藏索引”的一点思考
查看>>
使用Spring Data Redis操作Redis(二)
查看>>
通过QQ或者QQ帮助别人学习Lync之二
查看>>
【翻译】Ext JS——高效的编码风格指南
查看>>
Cisco c3560三层交换机配置
查看>>
统一沟通-技巧-10-Lync-公网域名-Go Daddy
查看>>
SystemCenter2012SP1实践(33)离线申请证书与远程桌面证书
查看>>
华为IT解决方案高举高打
查看>>
如何快速的提高自己:一切取决于你自己
查看>>
蔺永华:虚拟化你的大数据应用
查看>>
惠普渠道重新回归
查看>>
针对Redis队列的理解,实例操作
查看>>