Poj 3093 01 backpack

Source: Internet
Author: User
View code

 /*  Give you n items, each of which has a certain volume, give you a certain total volume of a certain backpack, ask you to use this backpack to install these items, there are several different combinations of items in a backpack. One combination is legal: The remaining backpack capacity must be the minimum size of the remaining items.  */  # Include <Cstdio> # Include <Cstring> # Include <Algorithm> Using   Namespace  STD;  Int DP [ 1010  ]; Int V [ 50  ];  Int Max ( Int A, Int  B ){  Return A> B? A: B ;}  Int  Main (){  Int T, I, J, K, V, D, CA = 1  ; Scanf (  "  % D " ,& T );  While (T -- ) {Scanf (  "  % D  " , & V ,& D );  For (I = 1 ; I <= V; I ++) scanf ( "  % D  " ,& V [I]); sort (V + 1 , V + 1 ); Int Sum = 0 , ANS = 0  ;  For (I = 1 ; I <= V; I ++ ){ //  Enumerate the smallest item in the list, which is smaller than him. Memset (DP, 0 , Sizeof (DP); DP [ 0 ] = 1 ; DP [Sum] =1  ;  For (J = I + 1 ; J <= V; j ++ )  For (K = D; k> = V [J] + sum; k -- ) DP [k] + = DP [k- V [J];  For (J = D; j> = max (D-V [I] + 1 , 1 ); J --) //  D-J + 1 <= V [I];                     If (J> = sum) ans + = DP [J]; sum + = V [I];} printf (  "  % D \ n  " , CA ++ , ANS );}} 

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.