[BOJ] 1890 점프

Time Lapse :NONE

1890.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;

#define MAXSIZE 100
int N;
int map[MAXSIZE][MAXSIZE];
long long cache[MAXSIZE][MAXSIZE];

long long dp(int x, int y)
{
if(x>=N||y>=N||map[x][y]==0)
return 0;

long long &ret = cache[x][y];
if(ret != -1)
return ret;

ret = dp(x+map[x][y], y)+dp(x,y+map[x][y]);
return ret;

}
int main(void)
{
cin>>N;
memset(cache,-1,sizeof(cache));
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
cin>>map[i][j];
}
}

cache[N-1][N-1]=1;
map[N-1][N-1]=1;
dp(0,0);
cout<<cache[0][0]<<endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/1890/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.