Skip to content

Commit c90362c

Browse files
authored
Merge pull request #48 from aayush96692/patch-5
max
2 parents 93bfa14 + ba1a6a3 commit c90362c

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

max

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
void printCombination(int [], int, int);
5+
void combinationUtil(int [], int [], int, int, int,int);
6+
7+
int ans;
8+
int main()
9+
{
10+
int T,N,K,A[1000],data[1000];
11+
cin>>T;
12+
for(int i=0;i<T;i++)
13+
{
14+
ans=0;
15+
cin>>N>>K;
16+
for(int j=0;j<N;j++)
17+
{
18+
A[j]=j+1;
19+
}
20+
printCombination(A,N,K);
21+
data[i]=ans;
22+
}
23+
for(int i=0;i<T;i++)
24+
{
25+
if(data[i]==1)
26+
cout<<"YES"<<endl;
27+
else
28+
cout<<"NO"<<endl;
29+
}
30+
return 0;
31+
}
32+
33+
void printCombination(int arr[], int n, int r)
34+
{
35+
int data[r];
36+
37+
combinationUtil(arr, data, 0, n-1, 0, r);
38+
}
39+
40+
void combinationUtil(int arr[], int data[], int start, int end,
41+
int index, int r)
42+
{
43+
if (index == r)
44+
{
45+
int N=end+1;
46+
for (int j=0; j<r; j++) {
47+
int sum=0;
48+
sum=sum+data[r];
49+
if(N==sum)
50+
ans=1;
51+
}
52+
return;
53+
}
54+
for (int i=start; i<=end && end-i+1 >= r-index; i++)
55+
{
56+
data[index] = arr[i];
57+
combinationUtil(arr, data, i+1, end, index+1, r);
58+
}
59+
}

0 commit comments

Comments
 (0)