首页 > 其他 > 详细

Codeforces Round #588 (Div. 2) A. Dawid and Bags of Candies

时间:2019-10-03 21:28:13      阅读:180      评论:0      收藏:0      [点我收藏+]

链接:

https://codeforces.com/contest/1230/problem/A

题意:

Dawid has four bags of candies. The i-th of them contains ai candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total?

Note, that you can‘t keep bags for yourself or throw them away, each bag should be given to one of the friends.

思路:

乱搞一下就行, 写了个背包

代码:

#include <bits/stdc++.h>
using namespace std;

int a[5], dp[1000];
int sum = 0;

int main()
{
    for (int i = 1;i <= 4;i++)
        cin >> a[i], sum += a[i];
    if (sum%2 == 1)
    {
        puts("NO");
        return 0;
    }
    for (int i = 1;i <= 4;i++)
    {
        for (int j = sum/2;j >= a[i];j--)
            dp[j] = max(dp[j], dp[j-a[i]]+a[i]);
    }
    if (dp[sum/2] == sum/2)
        puts("YES");
    else
        puts("NO");

    return 0;
}

Codeforces Round #588 (Div. 2) A. Dawid and Bags of Candies

原文:https://www.cnblogs.com/YDDDD/p/11620817.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!