일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 조합론
- 자바스크립트
- 미래는_현재와_과거로
- 크루스칼
- 회고록
- 문자열
- DP
- 세그먼트 트리
- dropout
- c++
- 가끔은 말로
- 이분 탐색
- 알고리즘
- 2023
- lazy propagation
- 플로이드 와샬
- 가끔은_말로
- BFS
- 분할 정복
- object detection
- pytorch
- 다익스트라
- NEXT
- back propagation
- 우선 순위 큐
- 너비 우선 탐색
- dfs
- tensorflow
- 백트래킹
- Overfitting
Archives
- Today
- Total
Doby's Lab
백준 14728번: 벼락치기 (C++) 본문
https://www.acmicpc.net/problem/14728
14728번: 벼락치기
ChAOS(Chung-ang Algorithm Organization and Study) 회장이 되어 일이 많아진 준석이는 시험기간에도 일 때문에 공부를 하지 못하다가 시험 전 날이 되어버리고 말았다. 다행히도 친절하신 교수님께서 아래와
www.acmicpc.net
Solved By: Knapsack DP
시간을 무게라고 두고, 배점을 가치라고 두었을 때, Knapsack DP를 돌려서 최대 이득 배점을 구해내면 됩니다.
#include <iostream>
using namespace std;
int cache[101][10001];
pair<int, int> test[101];
int n, t;
int main(){
cin >> n >> t;
for(int i = 1; i <= n; i++){
cin >> test[i].first >> test[i].second;
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= t; j++){
if(test[i].first <= j){
cache[i][j] = max(cache[i - 1][j], test[i].second + cache[i - 1][j - test[i].first]);
}
else{
cache[i][j] = cache[i - 1][j];
}
}
}
cout << cache[n][t];
return 0;
}
728x90
'PS > BOJ' 카테고리의 다른 글
백준 17128번: 소가 정보섬에 올라온 이유 (C++) (0) | 2022.07.03 |
---|---|
백준 13268번: 셔틀런 (Python) (0) | 2022.07.03 |
백준 16943번: 최대 페이지 수 (C++) (0) | 2022.06.29 |
백준 1535번: 안녕 (C++) (0) | 2022.06.29 |
백준 12865번: 평범한 배낭 (C++) (0) | 2022.06.29 |