[NOI1999] 01 skewers

Source: Internet
Author: User
Title Description

Given 7 integer N,A0,B0,L0,A1,B1,L1, it is required to design a 01-string s=s1s2...si...sn that satisfies:
1.si=0 or si=1,1<=i<=n;
2. For any contiguous length of S L0 sjsj+1...sj+l0-1 (1<=j<=n-l0+1), the number of 0 is greater than or equal to A0 and less than or equal to B0;
3. For any contiguous length of S L1 sjsj+1...sj+l1-1 (1<=j<=n-l1+1), the number of 1 is greater than or equal to A1 and less than or equal to B1;
For example, n=6,a0=1,b0=2,l0=3,a1=1,b1=1,l1=2, there is a 01-string s=010101 that satisfies all of the above conditions. Input Format

Only one row, with 7 integers, which in turn represents N,A0,B0,L0,A1,B1,L1 (3<=n<=1000,1<= a0<=b0<=l0<=n,1<=a1<=b1<=l1<=n), The adjacent two integers are separated by a space. output Format

Only one row, if there are no 01 strings that satisfy all the conditions, output an integer-1, otherwise the output satisfies the maximum of 1 of the 01 strings in all conditions. Sample Data Sample Input

6 1 2 3 1 1 2 sample output

3 Description

01 strings satisfying the conditions for 010101 problem Analysis


This problem should be special judge, and many OJ on the market are not added.
Set the binary string to T[1...N]
Set S[i] to the number of ' 1 ' in the first I character of T
Apparently, the latter one is only 1 bigger than the previous one.
Have
Si−si−1≤1 S_i-s_{i-1}\le 1
Si−1−si≤0 S_{i-1}-s_i\le 0
By the question, the number of 0 is greater than or equal to A0 and less than or equal to B0
The number of conversions to 1 is greater than or equal to l0-b0, less than or equal to l0-a0
So there are
Si−1−si+l0−1≤b0−l0 S_{i-1}-s_{i+l_0-1}\le B_0-l_0
SI+L0−1−SI−1≤L0−A0 S_{i+l_0-1}-s_{i-1}\le L_0-a_0
SI−1−SI+L1−1≤−A1 s_{i-1}-s_{i+l_1-1}\le-a_1
SI+L1−1−SI−1≤B1 S_{i+l_1-1}-s_{i-1}\le b_1
Because all is less than the character, differential constraints run the shortest possible time to find out s[i]
Then construct 01 sequence according to S[i]

Source Code

No special judge OJ please don't write according to my Code

#include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include < cstdlib> #include <vector> #include <cstdio> #include <cmath> #include <queue> using
namespace Std;
    inline const int Get_int () {int num=0,bj=1;
    Char X=getchar (); while (x< ' 0 ' | |
        X> ' 9 ') {if (x== '-') bj=-1;
    X=getchar ();
        } while (x>= ' 0 ' &&x<= ' 9 ') {num=num*10+x-' 0 ';
    X=getchar ();
} return NUM*BJ;
} const int maxn=2005;
struct Edge {int from,to,dist;};
    struct Difference_constraints {//differential constrained system int n,m;
    vector<edge>edges;
    vector<int>g[maxn];
    BOOL INQUE[MAXN];
    int DIST[MAXN],USED[MAXN];
        void init (int n) {this->n=n;
        Edges.clear ();
    for (int i=1; i<=n; i++) g[i].clear ();
        } void Addedge (int from,int to,int dist) {edges.push_back ((Edge) {from,to,dist});
       M=edges.size (); G[from].push_back (m-1);
    } void Insert (int x,int Y,int v) {//x-y<=v (flag=0), X-y>=v (flag=1) Addedge (Y,X,V);
        } bool SPFA (int s) {for (int i=1; i<=n; i++) Dist[i]=0x7fffffff/2;
        memset (inque,0,sizeof (Inque));
        deque<int>q;
        Q.push_back (s);
        dist[s]=0; inque[s]=

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.