BOJ 6144 - Charm Bracelet

image.png

단순한 냅색 문제이다.

void solve() {
   int n, m;
   cin >> n >> m;
   vi w(n), v(n);
   for (int i = 0; i < n; i++) cin >> w[i] >> v[i];
   int dp[12881]{};
   for (int i = 0; i < n; i++) {
      for (int j = m; j >= w[i]; j--) maxa(dp[j], v[i] + dp[j - w[i]]);
   }
   cout << *max_element(dp, dp + 12881);
}

Tags:

Categories:

Updated:

Comments