大佬求解(^v^)
2023-07-24 18:41:45
发布于:浙江
51阅读
0回复
0点赞
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1e9 + 7;
int countEscapePlans(vector<vector<int>>& gates) {
int N = gates.size();
int K = gates[0].size();
vector<vector<int>> dp(N, vector<int>(K, 0));
// 初始化边界条件
dp[0][0] = 1;
// 动态规划求解
for (int i = 0; i < N; i++) {
for (int j = 0; j < K; j++) {
if (i > 0) {
dp[i][j] += dp[i - 1][j];
dp[i][j] %= MOD;
}
if (j > 0) {
dp[i][j] += dp[i][j - 1];
dp[i][j] %= MOD;
}
}
}
return dp[N - 1][K - 1];
}
int main() {
int N, K;
cin >> N >> K;
vector<vector<int>> gates(N, vector<int>(K, 0));
for (int i = 0; i < N; i++) {
for (int j = 0; j < K; j++) {
cin >> gates[i][j];
}
}
int result = countEscapePlans(gates);
cout << result << endl;
return 0;
}
全部评论 1
求求辣
2023-07-24 来自 浙江
0
有帮助,赞一个