tile counting dynamic programming