Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BOJ-1932-정수 삼각형 #61

Open
changicho opened this issue Jan 15, 2020 · 0 comments
Open

BOJ-1932-정수 삼각형 #61

changicho opened this issue Jan 15, 2020 · 0 comments
Labels
clear 정답코드
Milestone

Comments

@changicho
Copy link
Owner

1932. 정수 삼각형

링크

난이도 정답률(_%)
Silver I 58.526

설계

메모이제이션

memo[i][j] = max(memo[i-1][j-1]+arr[i][j], memo[i-1][j-1]+arr[i][j])

일반항을 위와 같이 정할 수 있다.

index가 0미만이 되는 경우를 없애기 위해 배열의 0번째는 전부 빈칸으로 두고 1부터 시작한다.

정리

내 코드 (ms) 빠른 코드 (ms)
8

고생한 점

한동안 실행이 제대로 되지 않았다. 이유를 찾지 못함

코드

#include <algorithm>
#include <iostream>

using namespace std;

int map[502][502] = { 0, };
int memo[502][502] = { 0, };

void solution() {
	int N, sum = 0;

	cin >> N;

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= i; j++) {
			cin >> map[i][j];

			memo[i][j] = max(map[i][j] + memo[i - 1][j - 1], map[i][j] + memo[i - 1][j]);
		}
	}

	int answer = 0;
	for (int i = 0; i <= N; i++) {
		answer = max(answer, memo[N][i]);
	}

	cout << answer << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	solution();

	return 0;
}
@changicho changicho added the clear 정답코드 label Jan 15, 2020
@changicho changicho added this to the day8 milestone Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clear 정답코드
Projects
None yet
Development

No branches or pull requests

1 participant