"Exclusive Access 2 dilworth Theorem-like pressure dp"

<> Yes

<First update>


<Text>

Exclusive Access 2

Description

Point M given by N to FIG edges, directed to obtain directed acyclic graph, so that the longest shortest path.

N ≤ 15, M ≤ 100

Input Format

A first line number M (1≤M≤100).

Next M rows, each row two capital letters (L to the Z), up to 15 different outlet capital letters. Two capital letters in each line will not be the same.

Output Format

The first output line of the longest shortest path value of -1.

Sample Input

3
P Q
Q R
R P

Sample Output

1

Resolve

Dichotomous answer? I think too much.

A Conclusion: the longest chain acyclic graph points equal to the minimum number of division point set such that each point has focused on two paths do not exist.

Proof:
Since the two longest chain must not belong to the same set point, the set point is equal to the number of divisions greater than the length of the longest chain.

All the points we can each choose the degree zero of divided focus the same point, if there is a path between these points, and they are a degree \ (0 \) contradictions, so this division necessarily legal. Meanwhile, it sets the number of thus divided exactly the original length of the longest chain.

We actually disguised prove the famous \ (dilworth \) Theorem: POSETS longest chain is equal to its minimum anti-chain division.

Then enumerated directly set point, like its pre-press division manner is legitimate, then enumerated subset \ (DP \) can.

\(Code:\)

#include <bits/stdc++.h>
using namespace std;
const int N = 16;
int n,m,a[N][N],p[1<<N],f[1<<N];
vector < pair<char,char> > Link;
map <char,int> Hash;
int main(void)
{
    scanf("%d",&m);
    for (int i=1;i<=m;i++)
    {
        char c1,c2;
        cin >> c1 >> c2;
        Link.emplace_back(c1,c2);
        Hash[c1] = Hash[c2] = true;
    }
    map <char,int> :: iterator it;
    for (it=Hash.begin();it!=Hash.end();it++)
        it -> second = ++n;
    for ( auto e : Link )
        a[Hash[e.first]][Hash[e.second]] = a[Hash[e.second]][Hash[e.first]] = 1;
    memset( f , 0x3f , sizeof f );
    for (int S=1;S<1<<n;S++)
        for (int i=1;i<=n;i++)
            if ( S >> (i-1) & 1 )
                for (int j=i+1;j<=n;j++)
                    if ( S >> (j-1) & 1 )
                        p[S] |= a[i][j];
    f[0] = 0;
    for (int S=1;S<1<<n;S++)
        for (int T=S;T;T=S&(T-1))
            if ( p[T] == 0 )
                f[S] = min( f[S] , f[S^T] + 1 );
    printf("%d\n",f[(1<<n)-1]-2);
    return 0;
}

<Postscript>

Guess you like

Origin www.cnblogs.com/Parsnip/p/11520262.html