int get_val(int num) {
    int val = 0;
    val = num / 10  +  num % 10;
    return val;
}

/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 *
 * @param threshold int整型
 * @param rows int整型
 * @param cols int整型
 * @return int整型
 */
int movingCount(int threshold, int rows, int cols ) {
    // write code here
    int i, j, val = 0, count = 0;
    int temp[100][100] = {0};

    temp[0][0] = 1;

    for (i = 0; i < rows; i++) {
        for (j = 0; j < cols; j++) {
            int find = 0;
            val = get_val(i) + get_val(j);
            if (val <= threshold) {
                if (i - 1 >= 0) {
                    if (temp[i - 1][j] >= 1) {
                        find = 1;
                    }
                }
                if (j - 1 >= 0) {
                    if (temp[i][j - 1] >= 1) {
                        find = 1;
                    }
                }
                if (find == 1) {
                    temp[i][j] += 1;
                }
            }
        }
    }


    for (i = 0; i < rows; i++) {
        for (j = 0; j < cols; j++) {
            if (temp[i][j] >= 1) {
                count++;
            }
        }
    }
    return count;
}