https://blog.csdn.net/Bill_Yang_2016/article/details/53556021
Subject description
given seven integer N, A0, B0, L0, A1, B1, L1, 01 to design a string S = s1s2 ... si ... sN, satisfy:
1.si = 0 or si = 1,1 <= i <= N;
2. for any continuous length S of the substring L0 sjsj + 1 ... sj + L0-1 ( 1 <= j <= N-L0 + 1), the number is not less than 0 and less than A0 equal to B0;
3. for any continuous length S of the substring sjsj L1 + 1 ... sj + L1-1 (1 <= j <= N-L1 + 1), equal to the number greater than 1 and less than or equal to A1 Bl;
e.g., N = 6, A0 = 1 , B0 = 2, L0 = 3, A1 = 1, B1 = 1, L1 = 2, then the presence of all of the above conditions are satisfied a string of 01 S = 010101.
01 indicates the sequence number of the prefix 1 and, then you can use the inequality given subject and the presence of the prefix and the information itself, differential write inequality constraint algorithm S.
note! And representing the interval with the prefix and the prefix L and when the array is used to cut one.
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5+110; int n,a0,b0,l0,a1,b1,l1; int s[maxn]; int cnt; struct node{ int from,to,val,next; }edge[maxn]; int head[maxn]; void add(int u,int v,int val){ edge[cnt].from = u; edge[cnt].to = v; edge[cnt].val = val; edge[cnt].next = head[u]; head[u] = cnt; cnt++; } int push [maxNum], to [maxNum], whether [maxNum]; const int Inf = 0x3f3f3f3f ; bool spfa(){ for(int i=0; i<=n; i++){ December [i] = 0 ; view [i] = 0 ; dis[i] = inf; Surely, [i] = 0 ; } dis[0] = 0; vis[0] = 1; a [ 0 ] ++ ; queue<int> q; q.push(0); while(!q.empty()){ int u = q.front(); q.pop(); vis[u] = 0; for(int i=head[u]; i; i=edge[i].next){ int v = edge[i].to; int w = edge[i].val; if(dis[v] - dis[u] > w){ dis[v] = dis[u] + w; if(!vis[v]){ Surely [v] ++ ; if (num [v]> = n) return false ; q.push(v); to [v] = 1 ; } } } } return true; } int main(){ int T=5; while(T--){ cin>>n>>a0>>b0>>l0>>a1>>b1>>l1; dis[0] = 0; cnt = 1; memset(edge,0,sizeof(edge)); memset(head,0,sizeof(head)); for(int i=1; i<=n; i++){ if(i+l0-1<=n){ the Add (I - . 1 I + L0 -, . 1 , - (L0-B0)); // NOTE! This is similar to prefix and the Add (L0 - I + 1 , I- 1 , - (- (L0-A0))); // time calculation section and the contents of the header prefixed to Save 1! ! } IF (I + L1- . 1 <= n-) { add(i-1,i+l1-1,-a1); add(i+l1-1,i-1,-(-b1)); } add(i-1,i,0); add(i,i-1,-(-1)); } bool flag=spfa(); if(flag==0) cout<<"-1"<<endl; else{ for(int i=1; i<=n; i++){ // cout<<dis[i]<<" "; if(dis[i]<dis[i-1]) cout<<'1'; else cout<<'0'; } cout<<endl; } } }