Test instructions
For a maze, find the number of paths to the lower-left corner to the lower-right corner.
Analysis:
Plug DP template problem, it is recommended to look at CDQ's paper and then look at the code, this code in the template based on a slight change. Paper Address http://wenku.baidu.com/view/ed2b3e23482fb4daa58d4b74.html
Code:
#include <iostream>using namespace std;const int maxd=16;const int hash=10007;const int state=1000024;int N,M;int M Aze[maxd][maxd];int code[maxd];int ch[maxd];struct hashmap{int head[hash],next[state],size;long Long state[STATE],f[ State];void init () {Size=0;f[0]=0;memset (head,-1,sizeof (Head));} void push (long long st,long long ans) {int h=st%hash;for (int 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) {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)); Long long st=0;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 Init () {char str[20];memset (maze,0,sizeof (Maze)); for (int i=1;i<=n;++i) {scanf ('%s ', str); for (int j=0;j<m;+ +J)if (str[j]== '. ') Maze[i][j+1]=1;}} void Dpblank (int i,int j,int cur) {int k,left,up;for (k=0;k
POJ 1739 Tony ' s Tour plug DP template problem