POJ2411 Mondriaan's Dream-shaped contour line voltage + dp

Portal

 

Sol

First, like the pressure it is very easy to think about

The general practice is probably enumerate each state judge then transferred

But this fact can contour dp

That is, from top to bottom, left to right put the box

Suppose we have now put $ (i, j) $ this location

So to fill this position affect how in fact this is the only position left upper position to its position this section of the state

From left to right then from top to bottom like this paragraph pressed together, represents a cover, 0 represents not being covered

$ F [i] [j] [s] $ denotes fill to the second $ (i, j) $, $ (i-1, j) $ to $ (i, j-1) $ state is s scheme Number

Transfer:

Principles are put on the line by line now consider filled, otherwise it will never be covered

If $ (i-1, j) = 0 $, i.e. not put above the grid, then only the discharge erected box

If $ (i-1, j) = 1, (i, j-1) = 0 $ i.e. put above the grid, the grid is not put on the left, then a block can be placed sideways

If $ (i-1, j) = 1 $ i.e. put above the grid, then the block can hold

Finally, note that the first line of the state

 

Code

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #define Ri register int
 5 #define ll long long
 6 #define mem(a,b) memset(a,b,sizeof(a))
 7 using namespace std;
 8 int n,m;
 9 ll f[130][1<<11];
10 int main()
11 {
12     while(1)
13     {
14         scanf("%d%d",&n,&m);
15         if(!n||!m)break;
16         mem(f,0);f[0][(1<<m)-1]=1;
17         for(Ri i=1;i<=n;i++)
18             for(Ri j=1,t=m*(i-1)+j;j<=m;j++,t++)
19                 for(Ri k=0;k<(1<<m);k++)
20                 if(f[t-1][k])
21                 {
22                     ll hhh=f[t-1][k];
23                     if(i>1 && !(k&1))
24                         f[t][(k>>1)|(1<<(m-1))]+=hhh;
25                     if(j>1 && !(k&(1<<(m-1))) && (k&1))
26                         f[t][(k>>1)|(1<<(m-1))|(1<<(m-2))]+=hhh;
27                     if(i==1||k&1)
28                         f[t][k>>1]+=hhh;
29                 }
30         printf("%lld\n",f[n*m][(1<<m)-1]);
31     }
32     return 0;
33 }

 

Guess you like

Origin www.cnblogs.com/forward777/p/10958581.html