"Codeforces 567F" mausoleum

Source: Internet
Author: User

The last question of winter vacation is finished. ^∀^

Test instructions

1 to n each number has two, ranked first does not drop after the sequence of non-ascending, such as 112332, and satisfies the K shape such as 3 <= 6 for the third number to ≤ the sixth number of such a constraint requirements, how many kinds of row.


Interval Dp,dp[i][j] Indicates the number of scenarios where only the interval [i,j] has not been filled.

B[I][J] represents the number constraint relationship for position I and J.

Then start the platoon from both ends and place the two number T on either side or the same side at a time.

dp[i+1][j-1]+=dp[i][j];//on both sides.

dp[i+2][j]+=dp[i][j];//on the left.

dp[i][j-2]+=dp[i][j];//on the right.

and to satisfy the constraint conditions. If I position is less than J position, then I position must be placed first.

That is, the number of,< (≤) placed in the position at the current position on the Count of > (≥) has been placed.

and two positions each time if there is a constraint relationship, can only contain = (=, ≥, ≤).

When J==i+1, there is only one way to put the law, this time you can accumulate the answer.

When we put the number T, the length of the interval [i,j] is 2*n-2* (t-1), so j=i+2*n-(t-1) -1=2*n-2*t+i+1.

The number of scenarios is larger, so a long long is used.

#include <cstdio> #include <cstring> #define LL long long#define N 75int n,k;ll dp[n][n],ans;int b[n][n];//b[i    ][J] -2-1 3 1 2//i s J > >= = <= <int ch (int fl,int fr,int a,int c)//The number of positions in the row now is smaller than the free part { for (int i=fl; i<=fr; i++) if (b[a][i]==3| | b[c][i]==3| | b[a][i]<0| |    B[C][I]&LT;0) return 0; return 1;} int cc (int bl,int br,int a,int c) {//Now the number of positions in the row is greater than the portion of the large for (int i=1;i<=bl;i++) if (b[a][i]>0| |    B[C][I]&GT;0) return 0; for (int i=br;i<=2*n;i++) if (b[a][i]>0| |    B[C][I]&GT;0) return 0; return 1;} int check (int i,int j)//cannot be placed on two digits not allowed in the same position {return b[i][j]!=-2&&b[i][j]!=2;}    int main () {scanf ("%d%d", &n,&k);        for (int i=1; i<=k; i++) {int l,r,f=3;        Char s[5];        scanf ("%d%s%d", &l,s,&r);            if (s[0]== ' < ') {f=2;        if (s[1]) f--;            } else if (s[0]== ' > ') {f=-2;        if (s[1]) f++; } b[l][R]=f;    B[r][l]=f==3?f:-f;    } dp[1][2*n]=1;            for (int t=1, t<=n; t++) for (int i=1; i<=2*t-1; i++) {int j=2*n-2*t+i+1;                        if (Dp[i][j]) {if (j==i+1) {if (check (I,J))                ANS+=DP[I][J];                         } else {if (ch (i+1,j-1,i,j) &&cc (i-1,j+1,i,j) &&check (i,j))                    DP[I+1][J-1]+=DP[I][J];                    if (CH (i+2,j,i,i+1) &&cc (i-1,j+1,i,i+1) &&check (i,i+1)) dp[i+2][j]+=dp[i][j]; if (CH (i,j-2,j-1,j) &&cc (i-1,j+1,j-1,j) &&check (j-1,j)) dp[i][j-2]+=dp[i][                J];    }}} printf ("%lld", ans); return 0;}


"Codeforces 567F" mausoleum

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.