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

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

在这里输入题意

【题解】

判断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;
}


posted @ 2018-01-27 12:24  AWCXV  阅读(188)  评论(0编辑  收藏  举报