201301 JAVA题目0

#includebits/stdc++.h
using namespace std;
int Fab(int n)
{
    if(n0)return -n;
    return n;
}
bool dfs(int i,int sum,vectorintv,int ans)
{
    if(i==v.size())
    {
        if(ans==sum)return true;
        else return false;
    }
    return dfs(i+1,sum+v[i],v,ans)||dfs(i+1,sum-v[i],v,ans);
}
int main()
{
    int n;
    while(cinn)
    {
        vectorintv;
        int x,sum=0,sum3=0,sum5=0;
        for(int i=0; in; i++)
        {
            cinx;
            sum+=x;
            if(x==0)continue;
            else if(x%5==0)
            {
                sum5+=x;
            }
            else if(x%3==0)
            {
                sum3+=x;
            }
            else v.push_back(x);
        }
        if(sum%2)cout"false"endl;
        else if(dfs(0,0,v,Fab(sum3-sum5)))cout"true"endl;
        else cout"false"endl;
    }
    return 0;
}

最新回复(0)
/jishut6bhJz1YGJo1Xb_2BNJgzhGgLIzD2dvnj8tApOoIRmQHE_3D
8