POJ 1185 Artillery positions (pressure DP)

Source: Internet
Author: User

Topic Link POJ 1185

Today, Ai teaches a lot of line-segment trees, indicating that they do not move, to fill the front of the problem. Qaq

This question, I wrote the first time or as the previous HDU 2167, found that the impact of line I also used i-2 line, the previous method will not work.

Find out all the possible states because each row has a maximum of 10 columns, so there is a maximum of 4 in a row, and it does not have much of a viable state (most of the online statements are up to 60). Using dp[x][i][j] To transfer, x represents the X line, I represents the state of the X row, and J represents the state of the line x-1. Initialize the first two rows first.

1#include <cstdio>2#include <algorithm>3#include <cstring>4 using namespacestd;5 Const intMAXN = the;6 #defineLegal (A, B) (a&b)7 int Base[MAXN];8 intSTATE[MAXN];9 intSOLDERS[MAXN];Ten intDP[MAXN][MAXN][MAXN]; One Chars[maxn][ -]; A intnum =0; - intMain () - { the     intn,m; -scanf"%d%d",&n,&m); -      for(intI=0; i<n;i++) -     { +scanf"%s", S[i]); -          for(intj=0; j<m;j++) +         { A             if(s[i][j]=='H')Base[I]+= (1&LT;&LT;J);//Record Mountain at         } -     } -     intD =0; -      for(intI=0;i< (1&LT;&LT;M); i++)//Delete points in a row that attack each other -     { -         if(Legal (i,i<<1)|| Legal (i,i<<2))Continue; in         intK =i; -          while(k)//How many turrets are there in the record? to         { +solders[num]+= (1&k); -K=k>>1; the         } *state[num++] =i; $     }Panax Notoginseng      for(intI=0; i<num;i++)//Initialize line No. 0 -     { the         if(Legal (State[i),Base[0]))Continue; +dp[0][i][0] =Solders[i]; A     } the      for(intI=0; i<num;i++)//Initialize line 1th, this is the second row +     { -         if(Legal (State[i),Base[1]))Continue; $          for(intj=0; j<num;j++)//enumerate the first row $         { -             if(Legal (STATE[J),Base[0]))Continue; -             if(Legal (State[i],state[j]))Continue; thedp[1][I][J] = max (dp[1][i][j],dp[0][j][0]+solders[i]); -         }Wuyi     } the  -      for(intR=2; r<n;r++)//start enumerating from the second line Wu     { -          for(intI=0; i<num;i++)//Enumerate R rows About         { $             if(Legal (State[i),Base[R]))Continue; -              for(intj=0; j<num;j++)//Enumerate r-1 rows -             { -                 if(Legal (STATE[J),Base[R1]))Continue; A                 if(Legal (State[j],state[i]))Continue; +                  for(intk=0; k<num;k++)//Enumerate line r-2 the                 { -                     if(Legal (STATE[K),Base[R2]))Continue; $                     if(Legal (State[k],state[i]))Continue; the                     if(Legal (State[k],state[j]))Continue; theDP[R][I][J] = max (dp[r][i][j],dp[r-1][j][k]+solders[i]); the                 } the             } -         } in     } the     intMaxx =0; the      for(intI=0; i<num;i++) About     { the          for(intj=0; j<num;j++) theMaxx = Max (maxx,dp[n-1][i][j]); the     } +printf"%d\n", Maxx); -     return 0; the}

POJ 1185 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.