[POJ1185] Artillery positions (pressure DP)

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=1185

This is different from the previous one, in that the range of effects of a point is two lattices. Then DP (cur,pre,i) indicates how many methods can be used when the line I state is the Cur,i-1 row state is the pre. When the transfer is enumerated ppre, it is i-2 line. Divert

1 /*2 ━━━━━┒ギリギリ♂eye! 3 ┓┏┓┏┓┃キリキリ♂mind! 4 ┛┗┛┗┛┃\0/5 ┓┏┓┏┓┃/6 ┛┗┛┗┛┃ノ)7 ┓┏┓┏┓┃8 ┛┗┛┗┛┃9 ┓┏┓┏┓┃Ten ┛┗┛┗┛┃ One ┓┏┓┏┓┃ A ┛┗┛┗┛┃ - ┓┏┓┏┓┃ - ┃┃┃┃┃┃ the ┻┻┻┻┻┻ - */ -#include <algorithm> -#include <iostream> +#include <iomanip> -#include <cstring> +#include <climits> A#include <complex> at#include <fstream> -#include <cassert> -#include <cstdio> -#include <bitset> -#include <vector> -#include <deque> in#include <queue> -#include <stack> to#include <ctime> +#include <Set> -#include <map> the#include <cmath> * using namespacestd; $ #defineFr FirstPanax Notoginseng #defineSC Second - #defineCL Clear the #defineBUG puts ("Here!!!") + #defineW (a) while (a--) A #definePB (a) push_back (a) the #defineRint (a) scanf ("%d", &a) + #defineRll (a) scanf ("%i64d", &a) - #defineRs (a) scanf ("%s", a) $ #defineCIN (a) CIN >> a $ #defineFRead () freopen ("in", "R", stdin) - #defineFWrite () freopen ("Out", "w", stdout) - #defineRep (i, Len) for (int i = 0; i < (len); i++) the #defineFor (I, A, Len) for (int i = (a); I < (len); i++) - #defineCls (a) memset ((a), 0, sizeof (a))Wuyi #defineCLR (A, X) memset ((a), (x), sizeof (a)) the #defineFull (a) memset ((a), 0x7f7f7f, sizeof (a)) - #defineLRT RT << 1 Wu #defineRRT RT << 1 | 1 - #definePi 3.14159265359 About #defineRT return $ #defineLowbit (x) x & (-X) - #defineONECNT (x) __builtin_popcount (x) -typedefLong LongLL; -typedefLong DoubleLD; Atypedef unsignedLong LongULL; +typedef pair<int,int>PII; thetypedef pair<string,int>psi; -typedef PAIR&LT;LL, Ll>PLL; $typedef map<string,int>MSI; thetypedef vector<int>VI; thetypedef vector<ll>VL; thetypedef vector<vl>VVL; thetypedef vector<BOOL>vb; -  in Const intMAXN =101; the Const intMAXM = One; the CharTMP[MAXM]; About intdp[1<<maxm][1<<MAXM] [MAXN]; the intG[MAXN]; the intN, M; the  + BOOLOkintXinti) { -     if((x & G[i])! = x)return 0; the     if((x <<1) & x! =0)return 0;Bayi     if((x <<2) & x! =0)return 0; the     return 1; the } -  - signed Main () { the     //FRead (); the      while(~SCANF ("%d%d",&n,&m)) { the Cls (G); the         intMM =1<<m; -for (I,1, n+1) { the Rs (TMP); the              for(intj = m-1; J >=0; j--) { theG[i] <<=1;94G[i] |= (tmp[j] = ='P'?1:0); the             } the         } theRep (i, mm) {if(!ok (I,1))Continue;98dp[i][0][1] =__builtin_popcount (i); About         } -Rep (i, mm) {if(!ok (I,1))Continue;101Rep (J, mm) {if(!ok (J,2))Continue;102                 if(I & J)Continue;103dp[i][j][2] = max (dp[i][j][2], dp[i][0][1] +__builtin_popcount (i));104             } the         }106for (I,3, n+1) {107REP (cur, mm) {if(!ok (cur, i))Continue;108REP (pre, MM) {if(!ok (Pre, I-1))Continue;109                     if(Cur & Pre)Continue; the Rep (Ppre, mm) {111                         if(cur & pre) | | (cur & ppre) | | (Pre & Ppre))Continue; theDp[cur][pre][i] = max (Dp[cur][pre][i], dp[pre][ppre][i-1] +__builtin_popcount (cur));113                     } the                 } the             } the         }117         intRET =0;118 Rep (i, mm) {119 Rep (J, mm) { -RET =Max (ret, dp[i][j][n]);121             }122         }123printf"%d\n", ret);124     } theRt0;126}

[POJ1185] Artillery positions (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.