Serie A champions: Some existing 1*2 small boxes. 3*n how many rectangles to spell.
Thinking:
Because it is a recursive type. There's bound to be a layer of relationships. Careful observation, the study found that each layer should be set 21 layers. (The odd layer cannot be a rectangle) and the last battle from the last layer of the graphics card can be found. There are only two kinds of results ().
That
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxndu2otu5oa==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center "alt=" figure ">. Results two can be = = The result of the previous layer and the result of 22 results (very obvious. Don't say more, use strokes to know). Results one can ==2* (result one and result two of the previous layer) and result one. Why is it?
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxndu2otu5oa==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center "alt=" Figure 2 "> The previous layer of the two results can be derived from 1 and 22 cases respectively. That is, (result one and result two of the previous layer). And assuming that the previous layer is the result of a word can also extend a 3 case (above the symmetry of the result one can only extend one. Does not affect the result). Here, the recursive formula comes out.
If you look at the two sides not clear, please draw a picture according to three kinds of circumstances. The third type is the symmetry of the first.
Code:
#include <iostream> #include <cstdio> #include <cmath> #include <map> #include <queue># include<string> #include <cstring> #include <algorithm>using namespace Std;int dp[31][2];int main () { int n; dp[0][0]=1;//This kind of situation I very have no words, WA after really find not wrong to try out the dp[2][0]=1;dp[2][1]=2; for (int i=4;i<=30;i++) { dp[i][0]=dp[i-2][0]+dp[i-2][1]; DP[I][1]=3*DP[I-2][1]+2*DP[I-2][0]; } while (~SCANF ("%d", &n) &&n!=-1) { printf ("%d\n", dp[n][0]+dp[n][1]); } return 0;}
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
HDU 1143 Tri Tiling (Recursive)