Dynamic programming and maximum principle for discrete Goursat systems