Accepted necklace HDU 2660

Source: Internet
Author: User
Accepted neck.pdf

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1022 accepted submission (s): 406

Problem descriptioni
Have n precious stones, and plan to use K of them to make a neck.pdf
For my mother, but she won't accept a neck1_which is too heavy. Given
The value and the weight of each precious stone, please help me find
Out of the most valuable necklace my mother will accept.

Inputthe first line of input is the number of instances.
For each case, the first line contains two integers n (n <= 20 ),
The total number of stones, and K (k <= N), the exact number
Stones to make a necktasks.
Then n lines follow, each containing
Two integers: A (a <= 1000), representing the value of each precious
Stone, and B (B <= 1000), its weight.
The last line of each case contains an integer W, the maximum weight my mother will accept, W <= 1000.

Outputfor each case, output the highest possible value of the neck.pdf.

Sample input1
2 1
1 1
1 1
3

Sample output1

Source HDU boys' open session-from whu)

Recommendzty
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>

Int t, n, k, W;
Struct Node
{
Int V, W;
} P1 [2, 100];

Int sum = 0;

Void DFS (int v, int W, int num, Int J)
{

Int I;

If (W> W)
Return;
If (Num> K)
Return;
If (sum <v)
Sum = V;
For (I = J; I <n; I ++ ){
DFS (V + P1 [I]. V, W + P1 [I]. W, num + 1, I + 1 );
}

}

Int main ()
{
Int I, J;

Scanf ("% d", & T );
While (t --)
{
Sum = 0;
Scanf ("% d", & N, & K );
For (I = 0; I <n; I ++)
Scanf ("% d", & P1 [I]. V, & P1 [I]. W );
Scanf ("% d", & W );
DFS (0, 0, 0, 0); // parameter transfer, current value, value weight, current number, array subscript
Printf ("% d \ n", sum );
}
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.