Hdu3364 proud merchants (01 backpack)

Source: Internet
Author: User

In a certain sort of 01 backpack, it must be wrong to directly 01 the backpack, because the question is subject to some restrictions, you need to sort by Q-P from small to general items, as to why is it unclear?

View code

# Include <iostream>
# Include <algorithm>
Using Namespace STD;
Int DP [ 5005 ];
Struct Good
{
Int P, Q, V;
} G [ 505 ];
Bool CMP (good A, good B)
{
Return A. q-a.p <B. q-b.p;
}
Int Main ()
{
Int N, m;
While (Scanf ( " % D " , & N, & M) = 2 )
{
For ( Int I =0 ; I <n; I ++)
Scanf ( " % D " , & G [I]. P, & G [I]. Q, & G [I]. V );
Sort (G, G + N, CMP );
Memset (DP, 0 , Sizeof (DP ));
For ( Int I = 0 ; I <n; I ++)
{
For (Int J = m; j> = 0 ; J --)
{
If (J <G [I]. q | j-G [I]. P < 0 )
Continue ;
DP [J] = max (DP [J], DP [J-G [I]. p] + G [I]. V );
}
}
Int Ans = 0 ;
For ( Int I =0 ; I <= m; I ++)
If (DP [I]> ans)
Ans = DP [I];
Printf ( " % D \ n " , ANS );
}
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.