Poj 2411 new statement

Source: Internet
Author: User

Today I started srm, and PT thought of dp but I couldn't help it. But after reading rng_58's God code, I felt like a sea of Sky (staring at one afternoon, I can't bear to look straight,

TC is really a good place... Like!

In fact, it is to write the ordinary brick-laying problem in a way similar to the plug dp by Lattice recurrence. The following code should be understandable.

#include <cstdio>  #include <cstring>  #include <algorithm>  long long dp[2][1<<11]; int main() {     int n , m;     while(scanf("%d%d",&n,&m),n||m) {       int cur = 0 , nxt = 1;       dp[cur][0] =  1;        for(int i = 0; i < n; i++) {           for(int j = 0; j < m; j++) {             memset(dp[nxt],0,sizeof(dp[nxt]));             for(int s = 0; s < (1<<m); s++) if(dp[cur][s]){                 if(s&1){dp[nxt][s>>1] += dp[cur][s];continue;}                 if(j+1<m && !(s&2) ){                     int mask = ( s | 2 ) >> 1;                     dp[nxt][mask] += dp[cur][s];                 }                 if(i+1<n) {                     int mask = (s | (1<<m)) >> 1;                     dp[nxt][mask] += dp[cur][s];                 }             }             std::swap(cur,nxt);           }        }        printf("%I64d\n",dp[cur][0]);     }     return 0; } #include <cstdio>#include <cstring>#include <algorithm>long long dp[2][1<<11];int main() {    int n , m;    while(scanf("%d%d",&n,&m),n||m) {      int cur = 0 , nxt = 1;      dp[cur][0] =  1;       for(int i = 0; i < n; i++) {          for(int j = 0; j < m; j++) {            memset(dp[nxt],0,sizeof(dp[nxt]));            for(int s = 0; s < (1<<m); s++) if(dp[cur][s]){                if(s&1){dp[nxt][s>>1] += dp[cur][s];continue;}                if(j+1<m && !(s&2) ){                    int mask = ( s | 2 ) >> 1;                    dp[nxt][mask] += dp[cur][s];                }                if(i+1<n) {                    int mask = (s | (1<<m)) >> 1;                    dp[nxt][mask] += dp[cur][s];                }            }            std::swap(cur,nxt);          }       }       printf("%I64d\n",dp[cur][0]);    }    return 0;}

The following is the example of a year ago...


 

#include<stdio.h>  #include<string.h>  int h,w; __int64 dp[15][2050]; void dfs1(int row,int state,int col,int state2){     if(col>w) return ;     if(col==w) {         dp[row+1][state2]+=dp[row][state];         return ;     }     if(!(state&(1<<col))) dfs1(row,state,col+1,state2+(1<<col));     else dfs1(row,state,col+1,state2); } void dfs2(int row,int state,int col,int state2){     if(col>w) return ;     if(col==w) {         if(state2!=state)              dp[row][state2]+=dp[row][state];         return ;     }     if(!(state&(1<<col)) &&   !(state&(1<<(col+1))))         dfs2(row,state,col+2,state2+(1<<col) + (1<<(col+1)));     dfs2(row,state,col+1,state2); } void gao(){     int i,j;     dp[0][(1<<w)-1]=1;     for(i=0;i

 

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.