import itertools


def has_fset_with_last(f, b, g):
    """Return True if g contains f-set of order b containing vertex n-1.

    Arguments:
    f -- predicate
      Given a graph and a subset of its vertex set, returns bool.
    g -- graph
    b -- nonnegative int
      We search for an order-b f-set.

    See isograph.py for our graph representation.

    >>> g = [ [3], [3], [3], [0,1,2] ]
    >>> has_fset_with_last(is_independent, -1, g)
    False
    >>> has_fset_with_last(is_independent, 0, g)
    False
    >>> has_fset_with_last(is_independent, 1, g)
    True
    >>> has_fset_with_last(is_independent, 2, g)
    False
    >>> has_fset_with_last(is_independent, 3, g)
    False
    >>> has_fset_with_last(is_independent, 4, g)
    False
    >>> has_fset_with_last(is_clique, 1, g)
    True
    >>> has_fset_with_last(is_clique, 2, g)
    True
    >>> has_fset_with_last(is_clique, 3, g)
    False

    """
    if b < 1:
        return False

    n = len(g)
    if b > n:
        return False

    for ss in itertools.combinations(range(n-1), b-1):
        s = ss + (n-1,)
        if f(g, s):
            return True
    return False