C. Come to a spring outing

 

C. Come to a spring outing

Time Limit: 1000ms
Case Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format:  %lld      Java class name:  Main
Submit  Status  PID: 29358
Font Size:  +  -

    Spring is coming,WHU ACM team plans to organize a spring outing because of the good weather. They bought a lot of things to eat and use (collectively referred to the item), each item has a volume. In order to take them away, they also bought 3 backpacks, each backpack can be fitted to a certain volume of things, and the question is there: Can they take all the items away?

Input

    Input contains several test cases. The first line is an integer T indicates the number of test cases. For each test case, the first line is two integer n and m(1<=n<=30,1<=m<=400), indicate the number of items and the capacity of each backpack. The second line contains n integers, the i-th integer wi(1<=wi<=400) shows the volume of the i-th item.

Output

    For each set of data, output the case number first, and then output a string, “Yes” means they can take all things away, and “No” means they cannot take all things away by three backpack.

Sample Input

2
4 3
1 2 3 3
4 3
2 2 2 2

Sample Output

Case 1: Yes
Case 2: No
Submit  Status  PID: 29358


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int w[33];
int n,v;

bool cmp(int a,int b)
{
    return a>b;
}
bool OK=false;
void dfs(int i,int v1,int v2,int v3)
{
    if(i==n){ OK=true;  return; }
    if(OK==true) return;
    if(v1+w <=v)
        dfs(i+1,v1+w ,v2,v3);
    if(v2+w <=v)
        dfs(i+1,v1,v2+w ,v3);
    if(v3+w <=v)
        dfs(i+1,v1,v2,v3+w );
}

int main()
{
    int T;
    cin>>T;
    int cas=0;
while(T--)
{
    int sum=0;
    cin>>n>>v;
    for(int i=0;i<n;i++)
    {
        cin>>w ;  sum+=w;
    }

    if(sum>3*v)
    {
        printf("Case %d: No\n",++cas);
        continue;
    }
    OK=false;
    sort(w,w+n,cmp);
    dfs(0,0,0,0);

    if(OK)
        printf("Case %d: Yes\n",++cas);
    else
        printf("Case %d: No\n",++cas);
}

    return 0;
}


转载于:https://www.cnblogs.com/CKboss/p/3350915.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
In today's world, technology has made shopping more convenient than ever before. With the click of a button, we can purchase anything we want from the comfort of our homes. However, traditional shopping at a mall or a store is still relevant, and many people still prefer it over online shopping. Both methods of shopping have their advantages and disadvantages, and this essay will explore them in detail. Firstly, buying things online is convenient. It saves time and effort. Online shopping allows us to purchase anything we want from the comfort of our homes or offices. We can browse through thousands of products from different stores without having to move from one place to another. All we need is a device connected to the internet, and we can shop for anything we want. Online shopping also provides us with a wider range of products to choose from. We can find products that we cannot find in physical stores. Online stores have a vast inventory of products, and they can accommodate a larger variety of products than physical stores. This means we can find unique and rare items that we cannot find in physical stores. Additionally, online shopping allows us to compare prices easily. We can compare the prices of the same product from different stores and choose the one that offers the best value for our money. Another advantage of buying things online is that we can shop at any time of the day or night. Online stores are open 24/7, so we can shop at our convenience. This is particularly useful for people who have busy schedules and cannot find the time to go to physical stores during their operating hours. Additionally, online shopping allows us to avoid crowds and long lines. We can shop without having to deal with the hassle of finding a parking spot, navigating through crowded aisles, and waiting in long checkout lines. However, buying things online also has its disadvantages. One of the biggest disadvantages is that we cannot see or touch the product before making a purchase. This means we have to rely on product descriptions and images provided by the seller. Sometimes, the product we receive may not be as described or may be of poor quality. In such cases, returning the product can be a hassle, and it may take a long time to receive a refund. Another disadvantage of online shopping is that we have to wait for the product to be delivered. The delivery time can vary, depending on the location of the seller and the buyer. Sometimes, the product may get delayed or lost during transit, which can be frustrating for the buyer. Moreover, some online sellers may charge exorbitant shipping fees, which can add to the cost of the product. On the other hand, buying things at a shopping mall has its own advantages. One of the biggest advantages is that we can see and touch the product before making a purchase. We can inspect the product closely and get a better idea of its quality. This is particularly important when buying clothing, shoes, or any other product that requires a proper fit. Additionally, physical stores provide us with immediate gratification. We can take the product home with us right away, without having to wait for it to be delivered. Another advantage of shopping at a mall is that we can enjoy the social aspect of shopping. We can go shopping with friends or family members and make it a fun outing. We can also get advice and recommendations from salespeople, who are trained to help us find the right product for our needs. This can be particularly useful when buying products that we are not familiar with, such as electronic gadgets or appliances. Moreover, shopping at a mall allows us to support local businesses. Many small businesses operate within malls, and shopping at these stores can help support the local economy. Additionally, shopping at a mall can be a form of exercise. Walking around the mall can be a good way to burn calories and stay active. However, shopping at a mall also has its disadvantages. One of the biggest disadvantages is that it can be time-consuming. We have to travel to the mall, find a parking spot, and navigate through crowded aisles. This can take up a lot of time, particularly during peak shopping seasons. Moreover, shopping at a mall can be stressful. Crowded stores, long lines, and pushy salespeople can make the shopping experience unpleasant. Another disadvantage of shopping at a mall is that we may not find the product we are looking for. Physical stores have a limited inventory, and they may not have the product we want in stock. This can be frustrating, particularly if we have traveled a long way to buy a specific product. In conclusion, both online shopping and shopping at a mall have their advantages and disadvantages. Online shopping is convenient and offers a wider range of products to choose from. However, it lacks the tactile experience of physical shopping and can be risky if the product does not meet our expectations. Shopping at a mall provides us with the social aspect of shopping, immediate gratification, and the opportunity to support local businesses. However, it can be time-consuming, stressful, and may not offer the product we are looking for. Ultimately, the choice between online shopping and shopping at a mall depends on personal preferences and needs.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值