首页 > 其他 > 详细

力扣面试题13.机器人的运动范围

时间:2020-04-09 23:24:45      阅读:91      评论:0      收藏:0      [点我收藏+]

力扣面试题13.机器人的运动范围

技术分享图片

技术分享图片

class Solution {
    public:
    int get(int x)
    {
        int res = 0;
        while (x != 0)
        {
            res += x % 10;
            x /= 10;
        }
        return res;
    }
    // 机器人的运动范围
    int movingCount(int m, int n, int k)
    {
        if (!k) return 1;
        vector<vector<int>> temp(m, vector<int>(n, 0));
        temp[0][0] = 1;
        int res = 1;
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if ((i == 0 && j == 0) || get(i) + get(j) > k) continue;
                if (i - 1 >= 0)
                    temp[i][j] |= temp[i - 1][j];
                if (j - 1 >= 0)
                    temp[i][j] |= temp[i][j - 1];
                res += temp[i][j];
            }
        }
        return res;
    }
};

力扣面试题13.机器人的运动范围

原文:https://www.cnblogs.com/woodjay/p/12670309.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!