码迷,mamicode.com
首页 > 其他好文 > 详细

【Henu ACM Round#17 C】Kitahara Haruki's Gift

时间:2018-01-27 15:25:37      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:--   pre   clu   round   black   题解   gpo   main   post   

【链接】 我是链接,点我呀:)
【题意】


在这里输入题意

【题解】


判断sum/2这个价值能不能得到就可以了。
则就是一个01背包模型了。
判断某个价值能否得到。
f[j]表示价值j能否得到。
f[0] = 1;
写个01背包就好

【代码】

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

const int M = 100*200;
const int N = 100;

int f[M+10],n,a[N+10];;

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    #ifdef LOCAL_DEFINE
        freopen("rush.txt","r",stdin);
    #endif // LOCAL_DEFINE
    cin >> n;
    for (int i = 1;i <= n;i++) cin >> a[i];
    f[0] = 1;
    for (int i = 1;i <= n;i++)
        for (int j = M;j>=a[i];j--)
            if (f[j-a[i]]){
                f[j] = 1;
            }
    int sum = 0;
    for (int i = 1;i <= n;i++) sum+=a[i];
    sum/=2;
    if (f[sum]){
        cout <<"YES"<<endl;
    }else{
        cout <<"NO"<<endl;
    }
    return 0;
}

【Henu ACM Round#17 C】Kitahara Haruki's Gift

标签:--   pre   clu   round   black   题解   gpo   main   post   

原文地址:https://www.cnblogs.com/AWCXV/p/8365507.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!