Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define loop(i,b,e) for(int i=b;i<=e;i++)
- #define loop2(i,e,b) for(int i=e;i>=b;i--)
- typedef long long ll;
- typedef unsigned long long ull;
- int n,m;
- int t[15];
- map<string,int> mp;
- string s;
- void solve(int i,int sum,string ch,int took){
- if(sum>n)
- return;
- if(sum==n && took>=2){
- if(!mp[ch])
- cout<<ch << "="<< n <<endl;
- mp[ch]++;
- return;
- }
- if(i==m)
- return;
- s = to_string(t[i]);
- solve(i+1,sum+t[i],(ch=="") ? ch+s : ch + '+' +s,took+1);
- solve(i+1,sum,ch,took);
- }
- int main(){
- scanf("%d%d",&n,&m);
- loop(i,0,m-1)
- scanf("%d",&t[i]);
- sort(t,t+m);
- solve(0,0,"",0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement