Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions smsubset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <iostream>
using namespace std;
int g=21,garr[20];
void subarray(int *arr, int n, int x, int ans[], int m)
{if(x==0 && n>=-1)
{if(m<=g)
{g = m;
for(int j=0;j<g;j++)
garr[j] = ans[j];
}
return;
}
if(n<0)
return;
subarray(arr,n-1,x,ans,m);
ans[m] = arr[n];
subarray(arr,n-1,x-arr[n],ans,m+1);
return;
}
int main()
{int n,x,i,j=0,arr[20],ans[20],m=0,narr[20];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srijanakde2001 No indentation

cin>>n>>x;
for(i=n-1;i>=0;i--)
{cin>>arr[i];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indentation

narr[n-1-i] = arr[i];
}
subarray(arr,n-1,x,ans,m);
if(g==21)
cout<<"-1";
else
{for(i=0;i<n;i++)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indentation

{if(narr[i]==garr[j])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indentation

{if(j==0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indentation

cout<<i+1<<" ";
else
cout<<i+1<<" ";
j++;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indentation

if(j>=g)
break;
}
}
return 0;
}