Zoj 1100-mondriaan ' s Dream

Source: Internet
Author: User
Tags first row

Title: On the floor of the m*n the same 1*2 tile, ask how many kinds of paving method.

Analysis: DP, combination, count. Classic DP problem, state compression.

Status: Set F (i,j) for the front i-1 line, the first row of the state of the position expressed as J when the number of paving bricks;

Transfer: Because only horizontal or vertical paving, then a brick shop before the state only two kinds;

And if the current vertical position will affect the next line, establish two adjacent lines of state correspondence;

Here, Dfs is used to find all the pre-state f (i-1,k) plus and i,j of all the previous lines of f (a).

F (i,j) = SUM (f (i-1,k)) {where F (i-1,k) can produce an F (i,j) state};

(Rhubarb's three-dimensional DP implementation is simple and inefficient.) )

Combinatorial formula: π (4cos (pi+i/(h+1)) ^2+4cos (pi+j/(w+1)) ^2) {1<=I<=H/2,1<=J<=W/2}.

Description: Tangled n long last found%i64d has been WA. The%LLD is over. (2011-09-27 19:15).

#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct Node {int s,l;}
Seg

SEG s[10];

Long long f[[1<<11];
int v[1<<11 [99];

int count[1<<11]; Use DFS to find the status that can be reached in void Dfs (int A, int B, int C) {if (!
        A) {v[c] [+ count[c]] = B;
    Return 
        }else {int V = a&-a;//Gets the last 1 position of Dfs (A&~v, b&~v, C);
    if (a& (v<<1)) Dfs (a&~ (3*v), B, C);
    }} int main () {int n,m; while (scanf ("%d%d", &n,&m)! = EOF && m) {if (n%2&&m%2) {printf ("0\n"); contin
        UE;}
        
        if (m>n) {int t = M;m = N;n = t;}
        int M = (1<<m)-1;
            for (int i = 0; I <= M; + + i) {count[i] = 0;
        DFS (i, M, i);  } for (int i = 0; I <= N; + + i) for (int j = 0; J <= M; + + j) f[I [j]
      ] = 0LL;  f[0] [M] = 1LL; for (int i = 1; I <= n; + + i) for (int j = M; J >= 0;--j) for (int k = count[j]; K &G T;= 1;
        
        --K) f[I [j] + = f[i-1 [v[j] [K]];
    printf ("%lld\n", f[N [M]);
} 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.