HDU 2167 Pebbles (pressure DP)

Source: Internet
Author: User

This problem once again made no initialization of the problem, but the sample actually only the 2nd group is wrong, the others are right ... And it's impossible to debug ....

The problem is still a very simple form of pressure. Or the state of each row is preprocessed first. Then the state shifts from the first line down. In order to not tle, should be in each state and also pre-treatment.

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 __int64#define Pi ACOs ( -1.0) const int Mod=100000000;const int Inf=0x3f3f3f3f;const double eqs=1e    -8;int dp[20][1<<16], a[1<<16], top, tot, num[16][1<<16];int mp[20][20];void init (int n) {top=0;    int I, J; for (i=0;i<tot;i++) {if (!) (    i& (i<<1))) a[top++]=i;    }}int Main () {int n, m, I, J, X, Max1, K, H;    char c;        while (scanf ("%d", &mp[0][0])!=eof) {n=1;        C=getchar ();            while (c!= ' \ n ') {scanf ("%d", &mp[0][n++]);        C=getchar ();            } for (i=1;i<n;i++) {for (j=0;j<n;j++) {scanf ("%d", &mp[i][j]);        }} tot=1<<n;        Init (n);        memset (num,0,sizeof (num)); for (i=0;i<n; i++) {for (j=0;j<top;j++) {for (k=0;k<n;k++) {if (a[j]& (1<<k)) {                    NUM[I][J]+=MP[I][K];        }}}} memset (Dp,0,sizeof (DP));        max1=0;            for (i=0;i<top;i++) {dp[0][i]=num[0][i];        Max1=max (Max1,dp[0][i]); } for (i=1;i<n;i++) {for (j=0;j<top;j++) {for (k=0;k<top;k++) {i F ((A[j]&a[k]) | | (a[k]& (a[j]<<1)) | | (a[j]& (a[k]<<1)))                    Continue;                Dp[i][j]=max (Dp[i][j],dp[i-1][k]+num[i][j]);            } max1=max (Max1,dp[i][j]);    }} printf ("%d\n", max1); } return 0;}


HDU 2167 Pebbles (pressure DP)

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.