forked from Jasmine-21/Java-FOP
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathincreasingsequence.java
More file actions
37 lines (34 loc) · 1.1 KB
/
increasingsequence.java
File metadata and controls
37 lines (34 loc) · 1.1 KB
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
import java.util.*;
public class increasingsequence {
static int count = 0;
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = s.nextInt();
int k = s.nextInt();
numberOfIncresingSubSequences(arr, n, k);
}
static void numberOfIncresingSubSequences(int[] arr, int n, int k) {
int[] temp = new int[k];
int len = 0;
countIncreasingSubsequences(arr, n, k, temp, len);
System.out.println(count);
} static void countIncreasingSubsequences(int[] arr, int n, int k, int[] temp, int len) {
if (len > 1 && arr[temp[len - 1]] <= arr[temp[len - 2]])
return; if (len == k) {
count++;
return;
} int i;
if(len==0)
i=0; else
i=temp[len-1]+1;
len++; while (i < n) {
temp[len - 1] = i;
countIncreasingSubsequences(arr, n, k, temp, len);
i++;
}
len--;
}
}