描述 | |
---|---|
知识点 | 字符串,循环,函数,指针,枚举,位运算,结构体,联合体,文件操作,递归 |
运行时间限制 | 10M |
内存限制 | 128 |
输入 | 输入输入的数据个数 输入一个int型数组 |
输出 | 返回true或者false |
样例输入 | 4 1 5 -5 1 |
样例输出 | true |
#include<iostream>
using namespace std;
bool finds(int shu[],int length,int current,int sum)
{
if(current>=length)return false;
else if(shu[current]%3==0||shu[current]>sum)
return finds(shu,length,current+1,sum);
else if(shu[current]<sum)
return finds(shu,length,current+1,sum-shu[current])||finds(shu,length,current+1,sum);
else
{
bool check=true;
for(int i=current+1;i<length;i++)
{
if(shu[i]%5==0)
{
check=false;
}
}
return check||finds(shu,length,current+1,sum);
}
}
int main()
{
int ch[1024],n,sum=0;
cin>>n;
for (int i=0;i<n;i++)
{
cin>>ch[i];
sum+=ch[i];
}
if(sum%2!=0)cout<<"false"<<endl;
else if(finds(ch,n,0,sum/2))cout<<"true"<<endl;
else cout<<"false"<<endl;
return 0;
}