Problem P: 算式等式
Description
给你N个数字,每个数字均不相同,你可以取其中任意个数字相加,如果所得到的结果在给出的数列
中也能找到,则输出这个等式
Input
第一行一个数字N
接下来N个数字
Output
输出你找到的等式,注意看样例的输出格式
Sample Input
6
1 3 5 7 8 9
Sample Output
1+7=8
1+8=9
3+5=8
1+3+5=9
HINT
一层一层枚举去遍历,然后就可以找到方案。
#include<iostream>
using namespace std;
int n,m;
int a[1000],tot[1000];
void dfs(int dep,int cnt,int sum){
if(dep==m+1){
bool cmp=false;
for(int i=1;i<=n;i++){
if(sum==a[i]){
cmp=true;
break;
}
}
if(cmp==true){
for(int i=1;i<=m;i++)
if(i<m)cout<<tot[i]<<"+";