Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 정렬
- MAP
- 동적계획법
- DP
- String
- 리시프
- unordered_map
- substr
- vector
- 스택
- dfs
- 코딩테스트연습
- 다익스트라
- 플로이드와샬
- Dijkstra
- C++
- 최대공약수
- 백준
- set
- 참고 문헌 : MACHINE LEARNING 기계학습 _ 오일석
- 프로그래머스
- sql고득점kit
- 알고리즘
- MySQL
- 코테
- 코테준비
- 다이나믹프로그래밍
- 우선순위큐
- 문자열
- 시스템콜
Archives
- Today
- Total
YeJin's Footsteps
1890번: 점프 본문
문제 링크
https://www.acmicpc.net/problem/1890
문제 풀이 코드
#include <iostream>
using namespace std;
const int MN = 101;
long long dp[MN][MN];
int input[MN][MN];
int main(void){
ios::sync_with_stdio(false); cin.tie(NULL);
int n; cin>>n;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
int m; cin>>m;
input[i][j]=m;
}
}
dp[0][0]=1;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(dp[i][j]==0||(i==n-1&&j==n-1)) continue;
if((i+input[i][j])<n) dp[i+input[i][j]][j] += dp[i][j];
if((j+input[i][j])<n) dp[i][j+input[i][j]] += dp[i][j];
}
}
cout<<dp[n-1][n-1];
return 0;
}
* 처음 제출 시 틀린 부분
dp문제이고 dp배열에 전의 경우의 수가 축적 되기 때문에
if((i+input[i][j])<n) dp[i+input[i][j]][j] += 1;
if((j+input[i][j])<n) dp[i][j+input[i][j]] += 1;
이 아닌
if((i+input[i][j])<n) dp[i+input[i][j]][j] += dp[i][j];
if((j+input[i][j])<n) dp[i][j+input[i][j]] += dp[i][j];
위의 식으로 풀어야한다.
'Computer Science & Engineering > 알고리즘' 카테고리의 다른 글
거리두기 확인하기 (0) | 2021.09.10 |
---|---|
2011번: 암호코드 (0) | 2021.08.07 |
2407번: 조합 (0) | 2021.08.06 |
2 x n 타일링 (0) | 2021.07.31 |
문자열 압축 (0) | 2021.07.30 |
Comments