POJ 3254 Corn fields (pressure dp+ scrolling array)

Source: Internet
Author: User

Title Address: POJ 3254

Water-like pressure problem.

All possible occurrences of each line are preprocessed first. You can then save it with a vector.

The first line is then processed in all cases. And then from the second line began to continuously with the previous line of state transfer, state transfer is very simple not to say.

Finally, the number of the last line is counted and it can be.

The code is as follows;

#include <iostream> #include <string.h> #include <math.h> #include <queue> #include < algorithm> #include <stdlib.h> #include <map> #include <set> #include <stdio.h>using namespace std; #define LL __int64const int mod=100000000;const int inf=0x3f3f3f3f;int a[20][20];int dp[3][1<<13];        Vector<int>vec[13];bool Judge (int x, int y, int m) {int i; for (i=0; i<m; i++) {if (x& (1<<i)) && (y& (1<<i))) retur        n 0; } return 1;}        int main () {int n, m, I, J, tot, K, h, flag, ans, tmp;        scanf ("%d%d", &n,&m);                for (i=0; i<n; i++) {for (j=0; j<m; J + +) {scanf ("%d", &a[i][j]);        }} tot=1<<m;                        For (i=0, i<n; i++) {for (j=0; j<tot; J + +) {flag=0;                   for (k=0; k<m; k++) {             if (j& (1<<k)) {if (!a[i][k]) {                                                flag=1;                                        Break                                                } if (k>0&& (j& (1<<k-1))) {                                                flag=1;                                        Break                                }}} if (!flag)                Vec[i].push_back (j);        }} for (i=0; I<vec[0].size (); i++) {dp[0&1][vec[0][i]]=1;        }//printf ("%d\n", Vec[0].size ());        ans=0;                for (I=1; i<n; i++) {memset (dp[i&1],0,sizeof (dp[i&1]));                        for (j=0; J<vec[i].size (); j + +) {Tmp=vec[i][j]; for (k=0; K<vec[i-1].size (); k++) {if (Judge (Tmp,vec[i-1][k], m)) {Dp[i&1][t                                        mp]+=dp[i-1&1][vec[i-1][k]];                                if (dp[i&1][tmp]>=mod) dp[i&1][tmp]%=mod;                                }} if (i==n-1) {ans+=dp[i&1][tmp];                                if (ans>=mod) Ans%=mod;                        printf ("%d\n", ans);        }}} if (N==1) {ans=vec[0].size ();        } printf ("%d\n", ans); return 0;}


POJ 3254 Corn fields (pressure dp+ scrolling array)

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.