HDU-4341 gold miner group backpack

Source: Internet
Author: User

If multiple vertices are connected to the origin, you need to group the first vertex as a separate vertex and the first two as a separate vertex... finally, you can group the backpack directly.

The Code is as follows:

# Include <cstdlib> # include <cstdio> # include <cstring> # include <algorithm> # define maxn 205 using namespace STD; int n, m, CNT [maxn], vis [maxn], idx; int f [40005]; struct node {int X, Y, T, V; bool operator <(node temp) const {return Y <temp. Y ;}// sort the Y axis to obtain the nearest vertex} e [maxn]; struct team {int T, V ;} P [maxn] [maxn]; bool inline (int A, int B) {return E [A]. x * E [B]. y = E [A]. y * E [B]. x;} void Init () {int St = 0, SV = 0; idx = 0; memset (VIS, 0, sizeof (VIS); memset (CNT, 0, sizeof (CNT )); for (INT I = 1; I <= N; ++ I) {If (! Vis [I]) {vis [I] = 1; ++ idx, ++ CNT [idx]; ST = E [I]. t, SV = E [I]. v; P [idx] [CNT [idx]. T = sT; P [idx] [CNT [idx]. V = SV; For (Int J = 1; j <= N; ++ J) {If (! Vis [J] & inline (I, j) {vis [J] = 1; ++ CNT [idx]; ST + = E [J]. t, SV + = E [J]. v; P [idx] [CNT [idx]. T = sT; P [idx] [CNT [idx]. V = SV ;}}}void solve () {memset (F, 0, sizeof (f); For (INT I = 1; I <= idx; ++ I) {// first take into account a group and obtain the optimal answer for (INT T = m; t> = 0; -- t) for this group) {// because only one item can be retrieved in a group, this loop is in the outer for (Int J = 1; j <= CNT [I]; ++ J) {If (T> = P [I] [J]. t) {f [T] = max (F [T], F [T-P [I] [J]. t] + P [I] [J]. v) ;}}} printf ("% d \ n", F [m]);} int main () {int CA = 0; while (scanf ("% d", & N, & M) = 2) {for (INT I = 1; I <= N; ++ I) {scanf ("% d", & E [I]. x, & E [I]. y, & E [I]. t, & E [I]. v);} Sort (E + 1, E + 1 + n); printf ("case % d:", ++ CA); Init (); solve ();} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.