博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FZU 1977 Pandora adventure (插头DP)
阅读量:6471 次
发布时间:2019-06-23

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

Problem 1977 Pandora adventure

Accept: 246    Submit: 816
Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

The pollution of the earth is so serious that people can not survive any more. Fortunately, people have found a new planet that maybe has life, and we call it "Pandora Planet".

 

Leonardo Da Vinci is the only astronaut on the earth. He will be sent to the Pandora Planet to gather some plant specimens and go back. The plant specimen is important to the people to decide whether the planet is fit to live or not.

 

Assuming that Da Vinci can only move in an N×M grid. The positions of the plant specimens he wants to collect are all marked by the satellite. His task is to find a path to collect all the plant specimens and return to the spaceship. There are some savage beasts in the planet. Da Vinci can not investigate the grid with the savage beast. These grids are also marked by the satellite. In order to save time Da Vinci could only visit each grid exactly once and also return to the start grid, that is, you can not visit a grid twice except the start grid. You should note that you can choose any grid as the start grid.

 

Now he wants to know the number of different paths he can collect all the plant specimens. We only care about the path and ignore where the start grid is, so the two paths in Figure 1 are considered as the same.

Figure 1

Input

The first line of the input contains an integer T (T≤100), indicating the number of cases. Each case begins with a line containing two integers N and M (1≤N, M≤12), the size of the planet is N×M. Each of the following N lines contains M characters Gij(1≤i≤N, 1≤j≤M), Gij denotes the status of the grid in row i and column j, where 'X' denotes the grid with savage beast, '*' denotes the safe grid that you can decide to go or not, 'O' denotes the plant specimen you should collect. We guarantee that there are at least three plant specimens in the map.

Output

For each test case, print a line containing the test case number (beginning with 1) and the number of different paths he can collect all the plant specimens. You can make sure that the answer will fit in a 64-bit signed integer.

Sample Input

2 2 2 OO O* 4 4 ***O XO** **O* XX**

Sample Output

Case 1: 1 Case 2: 7

Source

The 35th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest
 
题目链接:
题目类型:插头DP。
分析:很经典的插头DP题目。求回路数问题。但是此题是有的格子必须经过,有的格子不能经过,有的格子可以选择经过。
这样导致回路最后一个位置不确定。
所以每一个状态增加个标志位isend来记录是否形成回路。
代码:
/*FZU 1977简单回路数问题,N*M(1<=N,M<=12)的方格中有障碍点,必走点和非必走点因为回路只有一条,而形成回路的最后一个点又是不确定的。所以额外增加一个标志位来记录是否形成回路。如果已经形成回路,而后面又遇到插头或者必须走的点,则该方案不合法G++ 375ms*/#include
#include
#include
#include
using namespace std;const int MAXD=15;const int HASH=10007;const int STATE=100010;int N,M;int code[MAXD];int maze[MAXD][MAXD];//0表示障碍点,1表示非必走点,2表示必走点int ch[MAXD];int isend;//是否形成回路标记位struct HASHMAP{ int head[HASH],next[STATE],size; long long state[STATE],f[STATE]; void init() { size=0; memset(head,-1,sizeof(head)); } void push(long long st,long long ans) { int i,h=st%HASH; for(i=head[h];i!=-1;i=next[i]) 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)//注意要增加一个isend标记位{ for(int i=m;i>=0;i--) { code[i]=st&7; st>>=3; } isend=st&1;//isend标记位在st的最高一位}long long encode(int *code,int m)//增加isend标记位{ long long st=isend;//最高位 int cnt=1; memset(ch,-1,sizeof(ch)); ch[0]=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://jtpko.baihongyu.com/

你可能感兴趣的文章
html之div始终停留在屏幕中间部分
查看>>
AsyncTask的缺陷
查看>>
Spring中jdbcTemplate的用户实例
查看>>
[模板] 快速傅里叶变换/FFT/NTT
查看>>
DecimalFormat 数据格式设置 SimpleDateFormat时间格式的用法介绍 --转载
查看>>
Android 的Margin和Padding属性以及支持的长度单位
查看>>
653. Two Sum IV - Input is a BST
查看>>
HDU ACM 1050 Moving Tables
查看>>
Django templates加载css/js/image等静态资源
查看>>
Eclipse C + GTK2.0环境构筑
查看>>
caffe solver
查看>>
Rhel6-heartbeat+lvs配置文档
查看>>
[CF340D]Bubble Sort Graph/[JZOJ3485]独立集
查看>>
ORACLE分科目统计每科前三名的学生的语句
查看>>
第一次冲刺--查看活动详情用户场景分析
查看>>
0317复利计算的回顾与总结
查看>>
函数对象
查看>>
Sharepoint学习笔记—习题系列--70-573习题解析 -(Q70-Q72)
查看>>
最全最新个税计算公式---今天你税了吗?
查看>>
linux shell 正则表达式(BREs,EREs,PREs)差异比较(转,当作资料查)
查看>>