hyelie
hyelie
Hyeil Jeong
       
글쓰기    관리    수식입력
  • 전체보기 (495)
    • PS (283)
      • Algorithm (28)
      • PS Log (244)
      • Contest (6)
      • Tips (5)
    • Development (52)
      • Java (14)
      • Spring (23)
      • SQL (2)
      • Node.js (2)
      • Socket.io (3)
      • Study (4)
      • Utils (4)
    • DevOps (36)
      • Git (5)
      • Docker (4)
      • Kubernetes (2)
      • GCP (3)
      • Environment Set Up (8)
      • Tutorial (12)
      • Figma (2)
    • CS (74)
      • OOP (7)
      • OS (24)
      • DB (2)
      • Network (24)
      • Architecture (0)
      • Security (2)
      • Software Design (0)
      • Parallel Computing (15)
    • Project (15)
      • Project N2T (5)
      • Project ASG (0)
      • Project Meerkat (1)
      • Model Checking (7)
      • Ideas (2)
    • 내가 하고싶은 것! (34)
      • Plan (16)
      • Software Maestro (10)
      • 취준 (8)
hELLO · Designed By 정상우.
hyelie

hyelie

PS/PS Log

22.07.07. 풀었던 문제들

BOJ 단계별 DP 1단계

1463 1로 만들기

10844 쉬운 계단 수

2156 포도주 - 이문제.. 빡세다

#define _USE_MATH_DEFINES 
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>
#include <map>
#include <cmath>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, string> pis;

int main(void) {
	cin.tie(0);
	cout.tie(0);
	std::ios_base::sync_with_stdio(0);

	////////////////////// write your code below
	
	int n; cin>>n;
	vector<int> drinks(n+1), dp(n+1, 0);
	for(int i = 1; i<=n; i++) cin>>drinks[i];

	////////////// logic 1
	dp[1] = drinks[1];
	if(n >= 2) dp[2] = drinks[1] + drinks[2];
	if( n >= 3) dp[3] =max(drinks[3] + drinks[2], drinks[1] + drinks[3]);
	// dp[i] : i번째 잔을 마셨을 때 최대값

	for(int i = 4; i<=n; i++){
		dp[i] = max(max(dp[i-2] + drinks[i], dp[i-3] + drinks[i-1] + drinks[i]), dp[i-4] + drinks[i-1] + drinks[i]);
	}

	///////////// logic 2
	dp[1] = drinks[1];
	if(n >= 2) dp[2] = drinks[1] + drinks[2];
	// dp[i] : i번째 잔까지 봤을 때 최대값
	//		i번째를 마시지 않거나
	//		i-2번째 + i번째거나
	//		i-3번째 + i-1번째 + i번째거나

	for(int i = 3; i<=n; i++){
		dp[i] = max(max(dp[i-2] + drinks[i], dp[i-3] + drinks[i-1] + drinks[i]), dp[i-1]);
	}
	
	cout<<*max_element(dp.begin(), dp.end());

	//////////////////////

	return 0;
}

'PS > PS Log' 카테고리의 다른 글

22.07.09. 풀었던 문제들 - Codeforces #787 Div. 3 4/7 *** euler tour, path, circuit  (0) 2022.07.09
22.07.08. 풀었던 문제들  (0) 2022.07.08
22.07.06. 풀었던 문제들  (0) 2022.07.06
22.07.05. 풀었던 문제들  (0) 2022.07.05
22.07.04. 풀었던 문제들  (0) 2022.07.04
    hyelie
    hyelie

    티스토리툴바