How much... in 3D! Build blocks dp, 12446133 ..

Source: Internet
Author: User

How much... in 3D! Build blocks dp, 12446133 ..

Question link: Click the open link

Question:

The number of squares of 2*2 * N is calculated using the square of 1*1*2.

There are nine statuses for each layer.

0. All values are 1.

1,

00

__

0 indicates that this is null, __indicates that the two are lying on one square

2,

00

11

0 indicates that this is null, and 1 indicates that the square block is standing upright.

In this way, there are 8 states except 0th, and then simple transfer.

Other statuses are invalid and will not be involved in the calculation of answers, so you do not need to consider


#include <string>#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#include <queue>#include <set>#include <map>#include <vector>template <class T>inline bool rd(T &ret) {char c; int sgn;if(c=getchar(),c==EOF) return 0;while(c!='-'&&(c<'0'||c>'9')) c=getchar();sgn=(c=='-')?-1:1;ret=(c=='-')?0:(c-'0');while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');ret*=sgn;return 1;}template <class T>inline void pt(T x) {    if (x <0) {        putchar('-');        x = -x;    }    if(x>9) pt(x/10);    putchar(x%10+'0');}using namespace std;const int N = 1000100;const int mod = 1000*1000*1000+7;void add(const int &y,int& x){x += y;if(x >= mod) x-=mod;}int d[N][9];int main() {memset(d, 0, sizeof d);d[0][0] = 1;for(int i = 0; i < N-1; i++){add(d[i][1], d[i][0]);add(d[i][2], d[i][0]);add(d[i][4], d[i][0]);add(d[i][5], d[i][0]);add(d[i][6], d[i][0]);add(d[i][8], d[i][0]);if(i>1)add(d[i-2][0], d[i][0]);add(d[i][0], d[i+1][1]);add(d[i][0], d[i+1][3]);add(d[i][0], d[i+1][5]);add(d[i][0], d[i+1][7]);add(d[i][1], d[i+1][4]);add(d[i][2], d[i+1][4]);add(d[i][3], d[i+1][2]);add(d[i][4], d[i+1][2]);add(d[i][5], d[i+1][8]);add(d[i][6], d[i+1][8]);add(d[i][7], d[i+1][6]);add(d[i][8], d[i+1][6]);}int T, n;scanf("%d", &T);while(T--){scanf("%d", &n);printf("%d\n", d[n][0]);}return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.