프로그래머스
보행자 천국 C++
by paysmile
2019. 10. 8.
#include <vector>
#include <cstring>
using namespace std;
const int MAX = 501;
int MOD = 20170805;
int top[MAX][MAX],lefts[MAX][MAX];
int solution(int m, int n, vector<vector<int>> city_map) {
memset(top,0,sizeof(top));
memset(lefts,0,sizeof(lefts));
top[1][1] = lefts[1][1] = 1;
for(int i=1; i<=m; i++){
for(int j=1; j<=n; j++){
if(city_map[i-1][j-1] == 0){
top[i][j] += (top[i-1][j] + lefts[i][j-1])%MOD;
lefts[i][j] += (top[i-1][j] + lefts[i][j-1])%MOD;
}
else if(city_map[i-1][j-1] == 1){
top[i][j] = 0;
lefts[i][j] = 0;
}
else{
top[i][j] = top[i-1][j];
lefts[i][j] = lefts[i][j-1];
}
}
}
return top[m][n]%MOD;
}