bzoj-1194 Pandora's Box

Source: Internet
Author: User

Test instructions

Given s automata, each automaton has n nodes and m output nodes;

Each node has two successors ' 0 ' and ' 1 ', adds that character to the end of the current pass, and then goes to the next node;

Each time from No. 0 points, with an empty string, to the output node can choose to output the current string;

If an automaton x can output all the strings of another automaton Y can also be output, then Y is the x upgrade;

To find the maximum upgrade sequence;

s,n,m<=50;


Exercises

After a little consideration of the problem, it was found that the difficult place was the self-motive;

Let's talk about other places first.

Begin

If you know the upgrade relationship between all the automata, how can I find out the answer?

You can upgrade X to Y as an edge x->y, so the answer is the longest +1 in the graph;

However, if there is a ring in the graph, there is no meaning in the longest road when there is a positive weight ring.

If you consider a ring, all the automata on the ring must be equivalent!

So on the Tarjan strong connectivity components, shrink point, convert to DAG engage to engage in ...

It's too much trouble!

Two equal automata form a two-way side, and then kill one does not become a one-way edge;

Every time from the numbered Dalian to the small number of the side, the rest of the side will also be able to connect all the equivalent of the automatic machine;

That actually after the map to run directly Floyd is OK;

End

Where the water is finished, the hard place is gone;

How to determine whether an automaton can include another self-motive;

Consider violent promiscuity:

It is not possible to generate all the substrings, and the infinite substrings cannot be enumerated;

One step at a time, another automaton followed, go to the output node to see if the other can output?

It's a good idea, but to what extent?

In the examination room I was crazy, so I thought-I walk 50 steps to try?

It must not be so good to walk once, so go a few more times!

So every time judge walk 10^6/s/s times, each walk 50 steps;

Such a randomization algorithm ran run, feeling can cheat a little ... And then it's 90!

In fact, the positive solution is no worse than the distance;

The search for positive solutions is equivalent to a memory;

The status of the search can be expressed as an automaton x node number and an automaton y number, so the number of States is only 2500;

Determine whether there is a state in the arrival of the automatic x node can be output, and Y cannot output the situation;

This is O (n^2) processing a query, a total of O (s^2*n^2) complexity;



Code:


#include <queue> #include <stdio.h> #include <string.h> #include <algorithm> #define N 550# Define M 50000#define pr pair<int,int>using namespace Std;int ch[m][2],is[m],tot;int s,f[n][n],root[n];queue< Pr>q;int hash[n][n];bool judge (int a,int b) {int i,x,y;while (!q.empty ()) Q.pop (); Q.push (Pr (root[a],root[b])); hash[ 0][0]=1;memset (hash,0,sizeof (hash)), while (!q.empty ()) {X=q.front (). First,y=q.front (). Second;q.pop (); if (Is[x] &&!is[y]) return 0;if (ch[x][0]-root[a]<0| | ch[y][0]-root[b]<0| | ch[x][1]-root[a]<0| | ch[y][1]-root[b]<0) exit (0); if (!hash[ch[x][0]-root[a]][ch[y][0]-root[b]]) {hash[ch[x][0]-root[a]][ch[y][0]- Root[b]]=1;q.push (PR (ch[x][0],ch[y][0]));} if (!hash[ch[x][1]-root[a]][ch[y][1]-root[b]]) {Hash[ch[x][1]-root[a]][ch[y][1]-root[b]]=1;q.push (pr (ch[x][1],ch [Y] [1]));}} return 1;} int main () {int n,m,i,j,k,x,y,ans;scanf ("%d", &s), for (i=1;i<=s;i++) {scanf ("%d%d", &n,&m); Root[i]=tot +1;tot+=n;for (j=1;j<=m;j++) {scanf ("%d", &x); Is[x+root[i]]=1;} for (x=root[i];x<=tot;x++) {scanf ("%d%d", &ch[x][0],&ch[x][1]); ch[x][0]+=root[i];ch[x][1]+=root[i];}} memset (F,-0x3f,sizeof (f)); for (i=1;i<=s;i++) {for (j=1;j<i;j++) {if (judge (I,j)) f[i][j]=1;if (judge (j,i)) f[j][ I]=1;if (F[i][j]==1&&f[j][i]==1) f[i][j]=-0x3f3f3f3f;}} for (k=1;k<=s;k++) {for (i=1;i<=s;i++) {for (j=1;j<=s;j++) {F[i][j]=max (f[i][j],f[i][k]+f[k][j]);}}} for (i=1,ans=0;i<=s;i++) {for (j=1;j<=s;j++) {Ans=max (ans,f[i][j]);}} printf ("%d\n", ans+1); return 0;}



bzoj-1194 Pandora's Box

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.