-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14501.cpp
48 lines (43 loc) · 926 Bytes
/
14501.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// Created by vkdne on 2018-04-03.
//
#include <iostream>
#include <queue>
using namespace std;
int arr[16][2]; // 0 : 시간 1 : 이득
int sol;
int N;
struct counsil{
int profit;
int possible;
};
queue<counsil> q;
void bfs(){
while(q.size()){
counsil tmp = q.front();
if(sol < tmp.profit)
sol = tmp.profit;
q.pop();
for(int i = tmp.possible ; i <= N ; i++){
counsil next;
next.profit = tmp.profit + arr[i][1];
next.possible = i + arr[i][0];
if(next.possible <= N+1)
q.push(next);
}
}
}
int main(){
cin >> N;
for(int i = 1 ; i <= N ; i++){
cin >> arr[i][0] >> arr[i][1];
}
for(int i = 1 ; i <= N ; i++) {
if(i+arr[i][0] <= N+1) {
q.push({arr[i][1], i + arr[i][0]});
bfs();
}
}
cout << sol << endl;
return 0;
}