Python implementation for CYK algorithm