圆环回原点问题

链接:字节跳动高频题——圆环回原点问题

题解:

#include <iostream>
#include <vector>
using namespace std;

int func(int n) {
    int length  = 10;
    std::vector<std::vector<int>> dp(n+1, std::vector<int>(length, 0));
    dp[0][0] = 1;
    for (int step = 1; step <= n; ++step) {
        for (int j = 0; j < length; ++j) {
            dp[step][j] = dp[step-1][(j-1+length)%length] + dp[step-1][(j+1)%length];
        }
    }
    return dp[n][0];
}

int main() {
    int n = 2;
    cout << func(n) << endl;
}

猜你喜欢

转载自blog.csdn.net/INGNIGHT/article/details/132521476