Original title Address
Tiling variants, the practice is similar
Assuming the floor is long below this, gray is unable to fill the void, initially can be n blocks outside the floor filled with gray, easy to handle the boundary
Suppose now that a part has been processed from the back forward, the green brick represents already traversed, and the blue dashed box represents the sub-problem that has been calculated
Now you want to traverse the red border tiles
There are only two possible types of paving methods:
If you can shop down, it's easy to push to another sub-problem
If it's right, it's going to be a bit of a hassle, two possibilities.
The first possibility, there is a block of gray bricks, as shown, then the statute becomes a sub-problem
The second possibility, no gray bricks, below can also be placed sideways, then the statute into another sub-question
After finishing this step, you can continue to work on other bricks, as well as similar steps
Code:
1#include <cmath>2#include <cstdio>3#include <vector>4#include <iostream>5#include <algorithm>6#include <cstring>7 using namespacestd;8 9 #defineMax_n 128Ten One intN, T; A BOOLCan[max_n][max_n]; - BOOLU[max_n]; - BOOLD[max_n]; the - intMain () { - /*Enter your code here. Read input from STDIN. Print output to STDOUT*/ -CIN >>T; + while(t--) { -CIN >>N; + Amemset (U,0,sizeof(U)); atmemset (D,0,sizeof(d)); - for(inti =0; i < N; i++) { - CharC; -CIN >>C; -U[i] = c = ='0'?true:false; - } in for(inti =0; i < N; i++) { - CharC; toCIN >>C; +D[i] = c = ='0'?true:false; - } the *Memset (CAN,0,sizeof(Can)); $ for(inti =0; I <2; i++)Panax Notoginseng for(intj =0; J <2; J + +) -Can[n + i][n + j] =true; the + inti =N; A intj =N; the while(I >=0|| J >=0) { + if(--j >=0) { - if(!D[j]) { $CAN[I][J] = can[i][j +1]; $}Else { - if(U[i]) -CAN[I][J] |= Can[i +1][j +1]; the if(D[j +1]) { - if(!U[i])WuyiCAN[I][J] |= Can[i +1][j +2]; the if(U[i] && u[i +1]) -CAN[I][J] |= Can[i +2][j +2]; Wu } - } About } $ if(-I. >=0) { - if(!U[i]) { -CAN[I][J] = can[i +1][j]; -}Else { A if(D[j]) +CAN[I][J] |= Can[i +1][j +1]; the if(U[i +1]) { - if(!D[j]) $CAN[I][J] |= Can[i +2][j +1]; the if(D[j] && d[j +1]) theCAN[I][J] |= Can[i +2][j +2]; the } the } - } in } the thecout << (can[0][0] ?"YES":"NO") <<Endl; About } the return 0; the}
hackerrank# Hexagonal Grid