博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
URAL1519 Formula 1
阅读量:6333 次
发布时间:2019-06-22

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

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. There are at least 4 cells without gopher holes.

Output

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

Example

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

 

 

 

这算完全体的插头DP吧?

果然超麻烦

1 #include
2 #include
3 #include
4 #include
5 #define LL long long 6 using namespace std; 7 const int mod=100007; 8 const int mxn=650010; 9 struct edge{ 10 int v,nxt,id; 11 }e[2][mxn]; 12 int hd[2][mod+2],mct[2]; 13 LL f[2][mxn]; 14 int now,pre; 15 void add(int v,LL w){
//hash 16 int z=v%mod; 17 for(int i=hd[now][z];i;i=e[now][i].nxt){ 18 if(v==e[now][i].v){f[now][i]+=w;return;} 19 } 20 e[now][++mct[now]]=(edge){v,hd[now][z],z};hd[now][z]=mct[now]; 21 f[now][mct[now]]=w; 22 return; 23 } 24 int b[20]; 25 int n,m; 26 char mp[20][20]; 27 int main(){ 28 int i,j; 29 scanf("%d%d",&n,&m); 30 for(i=1;i<=n;i++)scanf("%s",mp[i]+1); 31 int ex,ey; 32 for(i=n;i;i--){ 33 for(j=m;j;j--)if(mp[i][j]=='.'){ex=i;ey=j;break;} 34 if(j)break; 35 } 36 for(i=1;i<=m;i++)b[i]=i<<1; 37 now=0;pre=1; 38 add(0,1); 39 LL ans=0; 40 for(i=1;i<=n;i++){ 41 for(int k=1;k<=mct[now];k++)e[now][k].v<<=2; 42 for(j=1;j<=m;j++){ 43 swap(now,pre); 44 for(int k=1;k<=mct[now];k++)hd[now][e[now][k].id]=0; 45 mct[now]=0; 46 //init 47 // printf("i:%d j:%d mp:%c\n",i,j,mp[i][j]); 48 for(int k=1;k<=mct[pre];k++){ 49 int v=e[pre][k].v; 50 int x=(v>>b[j-1])&3; 51 int y=(v>>b[j])&3; 52 LL w=f[pre][k]; 53 // printf("%d %d k:%d v:%d w:%I64d\n",i,j,k,v,w); 54 // printf("x:%d y:%d\n",x,y); 55 if(mp[i][j]=='.'){ 56 if(!(x+y)){ 57 if(mp[i+1][j]=='.' && mp[i][j+1]=='.') 58 add(v^(1<
<
>b[c])&3; 76 if(tmp==1)cnt++; 77 if(tmp==2)cnt--;//不能else 78 if(!cnt){add((v^(1<
<
<
=0;c--){ 95 int tmp=(v>>b[c])&3; 96 if(tmp==1)cnt++; 97 if(tmp==2)cnt--; 98 if(!cnt){add((v^(2<
<
<

 

转载于:https://www.cnblogs.com/SilverNebula/p/6435400.html

你可能感兴趣的文章
Sofire v1.0 开源——WinForm/SL/WebForm 的 Remoting(1)
查看>>
我的友情链接
查看>>
使用包ldap3进行Python的LDAP操作3
查看>>
【xinfanqie】9大方法迅速解决电脑黑屏问题
查看>>
CentOS6.4的ext4文件系统如何实现挂载大于16TB的磁盘分区
查看>>
the word of jews
查看>>
linux必知必会
查看>>
迭代输出
查看>>
RabbitMQ学习总结(6)——消息的路由分发机制详解
查看>>
DB_oracle11g服务器调整内存后报ORA-00845
查看>>
Git使用详细教程
查看>>
Python字符串格式化
查看>>
mysql执行计划初步解读1
查看>>
Spring学习总结(2)——Spring的常用注解
查看>>
我已不是我--素养训练课
查看>>
MyBatis学习总结(9)——使用MyBatis Generator自动创建代码
查看>>
namenode ha by zookeeper
查看>>
Java 使用 Redis
查看>>
MyBatis学习总结(五)——实现关联表查询
查看>>
大型网站技术架构(一)大型网站架构演化
查看>>