Number of squares (1) (HDU 1565-pressure DP)

Source: Internet
Author: User

Test instructions

Give you a n*n checkered checkerboard with a non-negative number in each lattice.
Take out a number of the number, so that any of the two number of the lattice does not have a common edge, that is, the number of the 2 lattice is not adjacent, and the number of the largest. Analysis: The direct enumeration of all conditions after compression time-out, so the first line all possible cases and get the corresponding and the situation, the State is only related to the previous row state, all with two arrays to save the current row state and the previous row state.
#include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <string> #include <cctype> #include <complex> #include <cassert> #include <utility> #include <cstring> #include <cstdlib># Include <iostream> #include <algorithm>using namespace std;typedef pair<int,int> pii;typedef long Long ll; #define Lson l,m,rt<<1#define Pi ACOs ( -1.0) #define Rson m+1,r,rt<<11#define all 1,n,1#define read fre Open ("In.txt", "R", stdin) const LL INFLL = 0x3f3f3f3f3f3f3f3fll;const int inf= 0x7ffffff;const int mod = 1000000007;int        N,now[20001],total[20001],a[20][20];int nnum,par[20001],dp[20001],dp1[20001];void State (int i,int k,int s,int sum) {            if (k>=n) {now[++nnum]=s;            Total[nnum]=sum;        Return } State (I,k+2,s| (        1<<k), sum+a[i][k]); State (i,k+1,s,sum);} void SolvE () {for (int i=0;i<n;++i) {nnum=0;        State (i,0,0,0);        Memset (Dp,0,sizeof (DP)); for (int j=1;j<=nnum;++j) for (int l=1;l<=nnum;++l) if ((Now[j]&now[l]) ==0) {Dp[j]=max (dp[j],d        P1[L]+TOTAL[J]);        } for (int l=1;l<=nnum;++l) {dp1[l]=dp[l];    }} int maxv=-1;    for (int i=1;i<=nnum;++i) {Maxv=max (maxv,dp1[i]); } printf ("%d\n", MAXV);} int main () {while (~SCANF ("%d", &n)} {for (Int. i=0;i<n;++i) for (int j=0;j<n;++j) scanf ("%d"        , &a[i][j]);        memset (dp1,0,sizeof (DP1));    Solve (); }return 0;}

  

Number of squares (1) (HDU 1565-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.