https://www.acmicpc.net/problem/4384
이게 문제 링크구염
table[x][y]인데,
i = 0 to n ;i += 1
인 루프에서
table[x][y]는 0~i번째 원소 중 x개를 고른 것의 값이 y인 게 있으면 참이 됩니당.
3
100
90
200
예시가 이렇게 있으면
처음엔
table [0][0]이 참이 되겠고 (원소를 하나도 안 골랐을때 0원이니까용)
i = 0일땐
table[1][100]이 참이 되겠네여
i = 1일땐
table[2][190]이랑
table[1][90]이 참이 되겠네요
이런식으로 쭉 해가면서
s = n/2번을 확인해주면 되겠습니다.
그래서 저는 이로케 푸럿슴미다
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 | using ll = long long; #include <tuple> #include <iostream> #include <vector> #include <algorithm> #include <limits> #include <queue> using namespace std; int n; vector<int> arr; bool table[101][50000]; const int _max = numeric_limits<int>::max() / 10; int main() { cin >> n; arr.resize(n); int sum = 0; for (auto &i : arr) { cin >> i; sum += i; } table[0][0] = true; for (int i = 0; i < n; ++i) // i번째 항을 합에 더할려고 함. for (int j = 0; j <= i;++j) // 지금까지 집합의 원소 중 j개를 고른 것들 for (int k = 0; k <= 45000; ++k) { if (table[j][k]) table[j + 1][k + arr[i]] = true; } int s = n / 2; int ret = _max; for (int k = 0; k <= sum; ++k) { if (!table[s][k]) continue; if (abs(sum - 2 * k) < abs(sum - 2 * ret)) ret = k; } int ret2 = sum - ret; if (ret2 < ret) swap(ret2, ret); cout << ret << ' ' << ret2 << endl; } | cs |
배열 활용하는거 너무 어렵습니다ㅠㅠ...
https://www.acmicpc.net/group/264
가입한 사람은 점점 늘어나는데
문제 푸는건 agibal님이랑 저밖에 없는것같아요..
아무나 환영하는것이에요!
댓글 0