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 |
Tags
- 알고리즘
- 시뮬레이션
- 우선순위큐
- java
- 완전탐색
- COSPROJAVA1급
- spring
- 백준
- PS
- YBMCOS
- 다익스트라
- BFS
- 다이나믹프로그래밍
- 재귀함수
- 자바PS
- 이젠 골드구현도 어렵네..
- 네트워크플로우
- deque
- dp
- 취득후기
- COSPRO
- QUICKSTARTGUIDE
- 구현
- 세그먼트트리
- DFS
- 엘라스틱서치
- GatherTown
- 게더타운시작
- 백준코딩테스트
- 01BFS
Archives
- Today
- Total
공부공간
BOJ - 10164 ) 격자상의 경로 본문
https://www.acmicpc.net/problem/10164
두가지 경우로 나누어 생각할 수있다.
격자상의 경로에서 중간점이 1)있는경우, 2)없는경우
없는 경우는 갈수있는 격자의 모든 경우의 수는
11111
12345
1361015
이런식으로 고등학교 수학에 나오는 방식으로 구할 수 있다.
dp[n][m] = dp[n-1][m] + dp[n][m-1]
카카오 1차 코테랑 비슷했던거 같다.
중간점이 있는경우에는
중간점을 기준으로 왼쪽위 오른쪽아래 2가지의 경우의수를 곱해주는 것으로 구할 수 있다.
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
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static int compute(int end_x , int end_y) {
int map[][] = new int[end_y+1][end_x+1];
for(int index = 0 ; index < end_x+1 ; index++) map[0][index] =1;
for(int index = 0 ; index < end_y+1 ; index++) map[index][0] =1;
for(int y = 1; y <end_y+1 ; y++) {
for( int x = 1 ; x < end_x+1 ; x++) {
map[y][x] = map[y-1][x] + map[y][x-1];
}
}
return map[end_y][end_x];
}
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String arg = br.readLine();
String arg_[] = arg.split(" ");
int N = Integer.parseInt(arg_[0]);
int M = Integer.parseInt(arg_[1]);
int K = Integer.parseInt(arg_[2]);
if(K == 0) {
System.out.println(compute(N-1,M-1));
}
else {
int x =K%M-1;
if(x <0) x = M-1;
int y = K/M;
if(K%M ==0) y--;
System.out.println(compute(x,y) * compute(M-x-1,N-y-1));
}
}
}
|
s |
결과는!!
당연히 맞았다.
'알고리즘 > Dynamic Programming' 카테고리의 다른 글
BOJ - 1699) 제곱수의 합 (0) | 2020.01.29 |
---|---|
BOJ - 11052) 카드 구매하기 (0) | 2020.01.29 |
프로그래머스 ) 종이접기 (0) | 2020.01.26 |
BOJ - 1003 ) 피보나치 함수 (0) | 2020.01.07 |
BOJ - 11054) 가장 긴 바이토닉 부분 수열 (0) | 2020.01.06 |
Comments