Created
March 29, 2020 03:49
-
-
Save niklasjang/c04053fcbc141004141487956eaedc0b to your computer and use it in GitHub Desktop.
[PS][완전탐색][N자리 K진수]/[BOJ][14501][퇴사]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int n=0; | |
| int input[20][2]; | |
| int ans = 0; | |
| /* | |
| depth : depth날짜의 일을 할지 말지 결정해야 한다. = depth-1일까지는 일을 완료한 상태이다. | |
| score : depth-1일까지 완료한 상태까지 번 돈 | |
| */ | |
| void recur(int depth, int score){ | |
| if(depth>=n){ | |
| ans = ans < score ? score : ans; | |
| return; | |
| } | |
| if(depth + input[depth][0] -1 <n){ //depth날짜의 일을 진행할 때 마지막날이 출근하는 날이면 가능 | |
| recur(depth+input[depth][0], score + input[depth][1]); | |
| } | |
| recur(depth+1, score); | |
| } | |
| int main(void){ | |
| cin.tie(NULL); | |
| ios::sync_with_stdio("false"); | |
| cin>> n; | |
| for(int i=0; i<n; i++){ | |
| cin>> input[i][0] >> input[i][1]; | |
| } | |
| recur(0,0); | |
| cout << ans <<"\n"; | |
| return 0; | |
| } |
Author
Author
//int형 return을 가지는 코드
#include <iostream>
#include <algorithm>
using namespace std;
int n = 0;
int dp[1000001];
int input[1000001][2];
//n = 4
//0 1 2 3 4(퇴사)
//1 1 1 1 x
//1 2 3 4 x
int recur(int curr) {
//return [curr,마지막날]의 일을 해서 얻을 수 있는 최대 돈
int ret = 0;
if (curr == n) return 0;
//input[curr]의 일을 못하는 경우
if (curr + input[curr][0] > n) return recur(curr + 1);
//input[curr]의 일을 할 수 있는 경우
return max(recur(curr+input[curr][0]) + input[curr][1],recur(curr+1));
}
int main(void) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> input[i][0] >> input[i][1];
}
cout << recur(0);
return 0;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//일단 일을 하고, 딱 N일 차에 일이 끝나는 경우에만 답을 갱신하는 코드