-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmax
More file actions
59 lines (54 loc) · 1010 Bytes
/
Copy pathmax
File metadata and controls
59 lines (54 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<iostream>
using namespace std;
void printCombination(int [], int, int);
void combinationUtil(int [], int [], int, int, int,int);
int ans;
int main()
{
int T,N,K,A[1000],data[1000];
cin>>T;
for(int i=0;i<T;i++)
{
ans=0;
cin>>N>>K;
for(int j=0;j<N;j++)
{
A[j]=j+1;
}
printCombination(A,N,K);
data[i]=ans;
}
for(int i=0;i<T;i++)
{
if(data[i]==1)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
void printCombination(int arr[], int n, int r)
{
int data[r];
combinationUtil(arr, data, 0, n-1, 0, r);
}
void combinationUtil(int arr[], int data[], int start, int end,
int index, int r)
{
if (index == r)
{
int N=end+1;
for (int j=0; j<r; j++) {
int sum=0;
sum=sum+data[r];
if(N==sum)
ans=1;
}
return;
}
for (int i=start; i<=end && end-i+1 >= r-index; i++)
{
data[index] = arr[i];
combinationUtil(arr, data, i+1, end, index+1, r);
}
}