Gidhub BE Developer

[BOJ] 14501. 퇴사

2018-10-16
goodGid

Problem

Problem URL : 퇴사


[1] Answer Code (18. 10. 16)

#include<iostream>
#include<vector>
#include<algorithm>
#define p pair<int,int>
using namespace std;

int n;
int ans;
vector<p> v;

void dfs(int idx, int cost){
    if( idx == v.size() ){
        ans = ans < cost ? cost : ans;
        return;
    }
    
    if( idx > v.size()){
        return ;
    }
    
    // Pick
    dfs(idx + v[idx].first, cost+v[idx].second);
    
    // Pass
    dfs(idx+1, cost);
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ans = -1;

    cin >> n;
    for(int i=0; i<n; i++){
        int a,b;
        cin >> a >> b;
        v.push_back(p(a,b));
    }
    
    dfs(0,0);
        
    cout << ans << endl;
    return 0;
}

Review

  • 삼성 역량 테스트 기출 문제

  • 단순 DFS


Comments

Content