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-2449-전구 #70

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

BOJ-2449-전구 #70

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

Comments

@changicho
Copy link
Owner

2449. 전구

링크

난이도 정답률(_%)
Platinum IV 43.173

설계

재귀로 dp를 구함

정리

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

고생한 점

코드

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cstring>

#define INF 987654321

using namespace std;

int dp[202][202] = { 0, };	// 전구 숫자 최대 200개
int arr[202];

int dynamic(int f, int b) {
	if (f == b) return 0;
	if (dp[f][b] != -1) return dp[f][b];

	dp[f][b] = INF;
	for (int k = f; k < b; k++) {
		int adder = arr[f] == arr[k + 1] ? 0 : 1;

		dp[f][b] = min(dp[f][b], dynamic(f, k) + dynamic(k + 1, b) + adder);
	}
	return dp[f][b];
}

void solution() {
	int N, K;
	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		cin >> arr[i];
	}

	memset(dp, -1, sizeof(dp));

	cout << dynamic(0, N - 1) << "\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 16, 2020
@changicho changicho added this to the day9 milestone Jan 16, 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