UVa 10664 Luggage (0-1 backpack)

Source: Internet
Author: User
Tags time limit

10664-luggage

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1605

Peter and his friends are in holiday, so they have decided to make a trips by car to know the north of Spain. They are seven people and They that two cars are the for enough their.

It ' s time to leave ... and a heap of suitcases are awaiting out of the cars. The drivers disagree about which suitcase must is put in each boot, because nobody one boot to wants more carry T Han the other one. Is it possible this two boots load with the same weight? (Obviously without unpacking the suitcases!)

Consider m sets of numbers representing suitcases weights, for each one, if it's must to decide T He suitcases into the boots, and the two boots weigh the same.

Input

The ' The ' input contains an integer, M, indicating the number of test cases. For each test case, the There is a line containing n integers (1<=n<=20) separated to single spaces. These integers are the weights of each suitcase. The sum of the weights of the suitcases is less or equal to kilograms.

Output

This article URL address: http://www.bianceng.cn/Programming/sjjg/201410/45376.htm

The output consists of M lines. The i-th line corresponds with the i-th set of suitcases weight and contains the string "YES" or "NO", depending on the PO Ssibility that's two boots load with the same weight for the respective test case.

31 2 1 2 12 3 4 1 2 5 10 50 3 503 5 2 7 1 7 5 2 8 9 1 25 15 8 3 1 38 45 8 1
Noyesyes

Water a water.

Complete code:

/*0.015s*/
    
#include <cstdio>  
#include <cstring>  
#include <algorithm>  
using namespace Std;  
    
int val[25], dp[205];  
    
int main ()  
{  
    int t, SUM, N, I, J;  
    char ch;  
    scanf ("%d", &t);  
    while (t--)  
    {  
        sum = n = 0;  
        Do
        {  
            scanf ("%d", &val[n]);  
            Sum + + val[n++];  
            ch = getchar ();  
        }  
        while (CH!= && ch!=-1);  
        if (sum & 1) puts ("NO");  
        else
        {  
            memset (DP, 0, sizeof (DP));  
            Sum >>= 1;  
            for (i = 0; i < n; ++i) for  
                (j = sum; J >= Val[i];--j)  
                    dp[j] = max (Dp[j], dp[j-val[i] + val[i]);  
            Puts (dp[sum] = = sum? "YES": "NO");  
        }  
    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.