티스토리 뷰
12920번: 평범한 배낭 2
첫 번째 줄에 N, M (1 ≤ N ≤ 100, 1 ≤ M ≤ 10,000) 이 빈칸을 구분으로 주어진다. N은 민호의 집에 있는 물건의 종류의 수이고 M은 민호가 들 수 있는 가방의 최대 무게다. 두 번째 줄부터 N개의 줄에
www.acmicpc.net
백준 소스코드 [C++] 12920 평범한 배낭 2
#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
#include <set>
#define all(v) v.begin(), v.end()
#define pii pair<int,int>
#define make_unique(v) v.erase(unique(v.begin(), v.end()), v.end())
typedef long long ll;
using namespace std;
int bag[10001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, value, weight,things,thing;
cin >> n >> m;
for (int i = 1;i <= n;i++) {
cin >> weight >> value >> things;
thing = 1;
while (0 < things) {
for (int j = m;weight * thing <= j;j--)
bag[j] = max(bag[j], bag[j - weight * thing] + value * thing);
things = things - thing;
thing = thing * 2;
if (things < thing) thing = 1;
}
}
cout << bag[m];
return 0;
}
'백준' 카테고리의 다른 글
백준 소스코드 [C++] 2470 두 용액 (0) | 2021.03.02 |
---|---|
백준 소스코드 [C++] 2467 용액 (0) | 2021.03.02 |
백준 소스코드 [C++] 2263 트리의 순회 (0) | 2021.03.01 |
백준 소스코드 [C++] 11478 서로 다른 부분 문자열의 개수 (0) | 2021.02.27 |
백준 소스코드 [C++] 13925 수열과 쿼리 13 (0) | 2021.02.25 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- MeTal
- 포드 풀커슨 알고리즘
- 벨만포드 시간복잡도
- test coverage
- 네트워크 플로우
- 에드몬드 카프 알고리즘
- IOS
- CompositionalLayout
- 최대 매칭
- WWDC16
- 강한 순환 참조
- 최단경로 문제
- mach-o
- 최단경로 알고리즘
- WWDC17
- 네트워크 유량
- rxswift
- 최단경로문제
- 컴퓨터 추상화
- HIG
- CPU와 Memory
- 다익스트라 시간복잡도
- observeOn
- WWDC19
- 부스트캠프 6기
- WWDC21
- Testable
- 벨만포드 알고리즘
- 코딩대회
- State Restoration
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함