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 |
Tags
- Dijkstra
- 참고 문헌 : MACHINE LEARNING 기계학습 _ 오일석
- 프로그래머스
- 동적계획법
- 코딩테스트연습
- 스택
- 다이나믹프로그래밍
- 플로이드와샬
- MySQL
- 시스템콜
- 최대공약수
- vector
- MAP
- 다익스트라
- C++
- 알고리즘
- String
- 문자열
- 우선순위큐
- DP
- substr
- sql고득점kit
- unordered_map
- 정렬
- dfs
- 코테
- 코테준비
- set
- 리시프
- 백준
Archives
- Today
- Total
YeJin's Footsteps
1890번: 점프 본문
문제 링크
https://www.acmicpc.net/problem/1890
1890번: 점프
첫째 줄에 게임 판의 크기 N (4 ≤ N ≤ 100)이 주어진다. 그 다음 N개 줄에는 각 칸에 적혀져 있는 수가 N개씩 주어진다. 칸에 적혀있는 수는 0보다 크거나 같고, 9보다 작거나 같은 정수이며, 가장
www.acmicpc.net
문제 풀이 코드
#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 |