Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 브루트포스
- 수학
- 자료구조
- 시뮬레이션
- 그리디 알고리즘
- BFS
- 스택
- Team Fortress 2
- DFS
- ue5
- Unreal Engine 5
- 백트래킹
- 유니온 파인드
- VR
- 다이나믹 프로그래밍
- XR Interaction Toolkit
- 트리
- 그래프
- 구현
- 누적 합
- 투 포인터
- 재귀
- 백준
- 알고리즘
- 문자열
- 유니티
- 정렬
- 우선순위 큐
- 다익스트라
- c++
Archives
- Today
- Total
1일1알
백준 7579번 앱 C++ 본문
다이나믹 프로그래밍으로 풀 수 있는 문제이다. 배낭 문제와 비슷하다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n, m;
int sum = 0;
vector<pair<int, int>> v;
vector<vector<int>> cache(101, vector<int>(10001, 0));
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
v = vector<pair<int, int>>(n + 1, { -1,-1 });
for (int i = 1; i <= n; i++) {
int input;
cin >> input;
v[i].first = input;
}
for (int i = 1; i <= n; i++) {
int input;
cin >> input;
sum += input;
v[i].second = input;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= sum; j++) {
if (j - v[i].second >= 0) {
cache[i][j] = max(cache[i][j],
cache[i - 1][j - v[i].second] + v[i].first);
}
cache[i][j] = max(cache[i][j], cache[i - 1][j]);
}
}
for (int i = 0; i <= sum; i++) {
if (cache[n][i] >= m) {
cout << i;
break;
}
}
}
'알고리즘' 카테고리의 다른 글
백준 4386번 별자리 만들기 C++ (0) | 2022.07.10 |
---|---|
백준 1647번 도시 분할 계획 C++ (0) | 2022.07.09 |
백준 10942번 팰린드롬? C++ (0) | 2022.07.07 |
백준 1806번 부분합 C++ (0) | 2022.07.03 |
백준 1197번 최소 스패닝 트리 C++ (0) | 2022.07.02 |