Hdu2660 accepted neck.pdf

Source: Internet
Author: User
Accepted neck.pdf

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

Problem descriptioni have n precious stones, and plan to use K of them to make a neck1_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 the most valuable
Neckpolicmy 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 of 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 Input

1 2 1 1 1 1 1 3 
 

Sample output

1 
 

Sourcehdu boys' Open Session-start a holiday before a girl (from
Whu)

Recommendzty

# Include <iostream> # include <limits> using namespace STD; int C, N, K, max_w; int max_val, sum_val, sum_w; struct node {int val; int W; int visit;} A [22]; void DFS (INT start, int count) // start point of the Start cycle, Count records the number of stones used {int I; If (sum_w> max_w) // pruning return; If (count> K) return; If (k = count & sum_w <= max_w) {If (max_val <sum_val) max_val = sum_val; return ;} for (I = start; I <n; I ++) // if (a [I]. visit = 0) {sum_val + = A [I]. val; sum_w + = A [I]. w; A [I]. visit = 1; DFS (I + 1, Count + 1); sum_val-= A [I]. val; sum_w-= A [I]. w; A [I]. visit = 0 ;}} int main () {int I; CIN> C; while (c --) {CIN> N> K; for (I = 0; I <n; I ++) {CIN> A [I]. val; CIN> A [I]. w; A [I]. visit = 0;} CIN> max_w; sum_w = sum_val = max_val = 0; DFS (0, 0); cout <max_val <Endl;} 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.