正文
增加 22 行删除 22 行
95 行未改动9697989910010110210310410510627 行未改动1341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082098 行未改动2182192202212222232242252269 行未改动95 行未改动int n, m, endx, endy;char pl[N][N];int state[2][K], tot[2], d, f[2][K], ans;namespace Hash //哈希表{const int HASH_MOD = 257483; //随便打的struct hash_table{int head[K], nxt[K];void insert(int x, int s)27 行未改动int DP(){for(int i = 1; i <= n; i ++ ){for(int j = 1; j <= tot[d]; j ++ ) //处理两行之间轮廓线的转移state[d][j] <<= 2;for(int j = 1; j <= m; j ++ ){d ^= 1;hsh.clear();for(int k = 1; k <= tot[d ^ 1]; k ++ ){int now_state = state[d ^ 1][k];int p1 = (now_state >> ((j - 1) << 1)) & 3; //插头1int p2 = (now_state >> (j << 1)) & 3; //插头2int s = f[d ^ 1][k]; //当前格子 DP 值if(!a[i][j]) //case 1: 格子是障碍{if(!p1 && !p2)hsh.insert(now_state, s); //直接继承当前状态}else if(!p1 && !p2) //case 2: 格子没有插头{if(a[i][j + 1] && a[i + 1][j])hsh.insert(now_state + 2 * bin[j] + bin[j - 1], s); //向两边各插一个插头}else if(!p1 && p2) //case 3: 只有插头 2{if(a[i][j + 1])hsh.insert(now_state, s); //插头同向if(a[i + 1][j])hsh.insert(now_state - bin[j] * p2 + bin[j - 1] * p2, s); //插头不同向}else if(p1 && !p2) //case 4: 只有插头 1{if(a[i][j + 1])hsh.insert(now_state - bin[j - 1] * p1 + bin[j] * p1, s);if(a[i + 1][j])hsh.insert(now_state, s); //这几行和上面大致相同}else if(p1 == 1 && p2 == 1) //case 5: 两个插头,且都是左括号{int rc = 1;for(int l = j + 1; l <= m; l ++ ) //找后一个和这个插头匹配的插头{if(((now_state >> (l << 1)) & 3) == 1) rc ++;if(((now_state >> (l << 1)) & 3) == 2) rc --;if(!rc) //找到了,抹掉这两个插头,改变另一个插头的配对{hsh.insert(now_state - bin[j] - bin[j - 1] - bin[l], s);break;}}}else if(p1 == 2 && p2 == 2) //case 6: 两个插头,且都是右括号{int lc = 1;for(int l = j - 2; l >= 0; l -- ) //和上面大致相同{if(((now_state >> (l << 1)) & 3) == 2) lc ++;if(((now_state >> (l << 1)) & 3) == 1) lc --;if(!lc){hsh.insert(now_state - 2 * bin[j] - 2 * bin[j - 1] + bin[l], s);break;}}}else if(p1 == 2 && p2 == 1) //case 7: 两个插头配对hsh.insert(now_state - 2 * bin[j - 1] - bin[j], s); //直接抹掉两个插头else if(i == endx && j == endy) //case 8: 到终点了,统计答案ans += s;}}}return ans;8 行未改动{for(int j = 1; j <= m; j ++ ){cin >> pl[i][j];a[i][j] = (pl[i][j] == '.');if(pl[i][j] == '.')endx = i, endy = j;}}9 行未改动95 行未改动9697989910010110210310410510627 行未改动1341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082098 行未改动2182192202212222232242252269 行未改动95 行未改动int n, m, endx, endy;char pl[N][N];int state[2][K], tot[2], d, f[2][K], ans;namespace Hash //哈希表{const int HASH_MOD = 257483; //随便打的struct hash_table{int head[K], nxt[K];void insert(int x, int s)27 行未改动int DP(){for(int i = 1; i <= n; i ++ ){for(int j = 1; j <= tot[d]; j ++ ) //处理两行之间轮廓线的转移state[d][j] <<= 2;for(int j = 1; j <= m; j ++ ){d ^= 1;hsh.clear();for(int k = 1; k <= tot[d ^ 1]; k ++ ){int now_state = state[d ^ 1][k];int p1 = (now_state >> ((j - 1) << 1)) & 3; //插头1int p2 = (now_state >> (j << 1)) & 3; //插头2int s = f[d ^ 1][k]; //当前格子 DP 值if(!a[i][j]) //case 1: 格子是障碍{if(!p1 && !p2)hsh.insert(now_state, s); //直接继承当前状态}else if(!p1 && !p2) //case 2: 格子没有插头{if(a[i][j + 1] && a[i + 1][j])hsh.insert(now_state + 2 * bin[j] + bin[j - 1], s); //向两边各插一个插头}else if(!p1 && p2) //case 3: 只有插头 2{if(a[i][j + 1])hsh.insert(now_state, s); //插头同向if(a[i + 1][j])hsh.insert(now_state - bin[j] * p2 + bin[j - 1] * p2, s); //插头不同向}else if(p1 && !p2) //case 4: 只有插头 1{if(a[i][j + 1])hsh.insert(now_state - bin[j - 1] * p1 + bin[j] * p1, s);if(a[i + 1][j])hsh.insert(now_state, s); //这几行和上面大致相同}else if(p1 == 1 && p2 == 1) //case 5: 两个插头,且都是左括号{int rc = 1;for(int l = j + 1; l <= m; l ++ ) //找后一个和这个插头匹配的插头{if(((now_state >> (l << 1)) & 3) == 1) rc ++;if(((now_state >> (l << 1)) & 3) == 2) rc --;if(!rc) //找到了,抹掉这两个插头,改变另一个插头的配对{hsh.insert(now_state - bin[j] - bin[j - 1] - bin[l], s);break;}}}else if(p1 == 2 && p2 == 2) //case 6: 两个插头,且都是右括号{int lc = 1;for(int l = j - 2; l >= 0; l -- ) //和上面大致相同{if(((now_state >> (l << 1)) & 3) == 2) lc ++;if(((now_state >> (l << 1)) & 3) == 1) lc --;if(!lc){hsh.insert(now_state - 2 * bin[j] - 2 * bin[j - 1] + bin[l], s);break;}}}else if(p1 == 2 && p2 == 1) //case 7: 两个插头配对hsh.insert(now_state - 2 * bin[j - 1] - bin[j], s); //直接抹掉两个插头else if(i == endx && j == endy) //case 8: 到终点了,统计答案ans += s;}}}return ans;8 行未改动{for(int j = 1; j <= m; j ++ ){cin >> pl[i][j];a[i][j] = (pl[i][j] == '.');if(pl[i][j] == '.')endx = i, endy = j;}}9 行未改动