51nod1522&cf567f up and down sequence/mausoleum DP

Source: Internet
Author: User

Topic Portal: Http://codeforces.com/problemset/problem/567/FRoughly test instructions: You have $1$ all positive integers to $n$ each number two, now you need to line it up into a sequence that makes the sequence a single-peak sequence (there is a $j \in [1,2n]$ satisfies $a_1 \leq a_2 \leq} ... \geq a_{2n}$), and satisfies the $k$ constraints given in the input. $N \leq, K \leq 100$ 
because the sequence is to satisfy a single peak, consider adding elements from small to large at the left and right of the sequence where no numbers are added, so that the sequence will always meet the one-peak properties
consider the state $f_{p,q}$ means that the left has been filled with $p$, the right to fill the $q$ of the scheme (in fact, can be pressed off one dimension), consider the transfer of the $i$ number, there are $3$ species:
$a: $ put these two $i$ on the leftmost of the sequence $b: $ put these two $i$ on the far right of the sequence; $c. $ Put one side of these two $i$.
for a $k$ constraint we can directly judge when we join: The number of two currently added is equal, the position not added must be larger than the current number of points, and the rest of the filled place must be smaller than the current number.
The final answer is $\frac{\sum\limits_{i=0}^{2n}f_{i,2n-i}}{3}$, except for 3 because for the last addition, $ABC $ three scenarios are possible, but we can only count one.
attention to the details of the constraint conditions, the storage of constraints can be used similar to the Adjacency table method, in the inclusion of the constraint conditions such as the addition of non-edge as the same as two constraints, it will be easier to judge.
1#include <bits/stdc++.h>2 #defineint long Long3 using namespacestd;4 5 intans[ the][ the], numop[ the];6 7Vector <int> num[ the], op[ the];8Map <string,int>Optonum;9 Ten BOOLIfok (intLintRintQue1,intque2) { One //pay special attention to the situation where the que1 position is connected to the que2 position A      for(inti =0; i < numop[que1]; i++) -         Switch(Op[que1][i]) { -              Case 1: the                 if(Num[que1][i] < R && Num[que1][i] > L | | num[que1][i] = =que2) -                     return 0; -                  Break; -              Case 2: +                 if(Num[que1][i] < R && Num[que1][i] > L && num[que1][i]! =que2) -                     return 0; +                  Break; A              Case 3: at                 if(! (Num[que1][i] = =que2)) -                     return 0; -                  Break; -              Case 4: -                 if(! (Num[que1][i] <= R && num[que1][i] >= l | | num[que1][i] = =que2)) -                     return 0; in                  Break; -              Case 5: to                 if(! (Num[que1][i] < R && Num[que1][i] > L) | | Num[que1][i] = =que2) +                     return 0; -         } the      for(inti =0; i < numop[que2]; i++) *         Switch(Op[que2][i]) { $              Case 1:Panax Notoginseng                 if(Num[que2][i] < R && Num[que2][i] > L | | num[que2][i] = =que1) -                     return 0; the                  Break; +              Case 2: A                 if(Num[que2][i] < R && Num[que2][i] > L && num[que2][i]! =que1) the                     return 0; +                  Break; -              Case 3: $                 if(! (Num[que2][i] = =que1)) $                     return 0; -                  Break; -              Case 4: the                 if(! (Num[que2][i] <= R && num[que2][i] >= l | | num[que2][i] = =que1)) -                     return 0;Wuyi                  Break; the              Case 5: -                 if(! (Num[que2][i] < R && Num[que2][i] > L) | | Num[que2][i] = =que1) Wu                     return 0; -         } About     return 1; $ } -  - Main () { -Optonum.insert (Make_pair (">",1)); AOptonum.insert (Make_pair (">=",2)); +Optonum.insert (Make_pair ("=",3)); theOptonum.insert (Make_pair ("<=",4)); -Optonum.insert (Make_pair ("<",5)); $     intN, K; the      for(Cin >> N >> K; K k--){ the         intA, B, t; the         strings; theCin >> a >> s >>b; -T = Optonum.find (s)second; in         if(A = =b) the             if(T = =1|| t = =5){ thecout <<0; About                 return 0; the             } the             Else the                 Continue; + Num[a].push_back (b); - Op[a].push_back (t); the Num[b].push_back (a);BayiOp[b].push_back (6-t); thenumop[a]++; thenumop[b]++; -     } -ans[0][0] =1; the      for(inti =1; I <= N; i++){ the     //DP the          for(intj =2I J >=2; j--) the             if(Ans[j-2][2* I-j] && Ifok (J,2N2* i + j +1, J, J-1)) -ans[j][2* I-j] + = ans[j-2][2Ij]; the          for(intj =2I J >=2; j--) the             if(ans[2* I-j][j-2] && Ifok (2* I-j,2* N-j +1,2* N-j +1,2* N-j +2)) theans[2* I-j][j] + = ans[2* I-j][j-2];94          for(intj =1; J <2I J + +) the             if(ans[2* I-j-1][j-1] && Ifok (2* I-j,2* N-j +1,2* I-j,2* N-j +1)) theans[2* I-j][j] + = ans[2* I-j-1][j-1]; the     }98     intall =0; About      for(inti =0; I <=2N i++) -All + = ans[i][2Ni];101cout << All/3;102     return 0;103}

51nod1522&cf567f up and down sequence/mausoleum 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.