File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
src/algorithms/largest_sequential_multiple_subsequence Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ package algorithms .largest_sequential_multiple_subsequence ;
2+
3+ import java .util .Scanner ;
4+
5+ public class Main {
6+ private void run () {
7+ Scanner scanner = new Scanner (System .in );
8+ int arraySize = scanner .nextInt ();
9+ int [] array = new int [arraySize ];
10+ for (int i = 0 ; i < arraySize ; i ++) {
11+ array [i ] = scanner .nextInt ();
12+ }
13+ int largestSubsequenceLength = calcLargestSequentialMultipleSubsequenceLength (array );
14+ System .out .println (largestSubsequenceLength );
15+ }
16+
17+ private int calcLargestSequentialMultipleSubsequenceLength (int [] array ) {
18+ int largestSubsequenceLength = 1 ;
19+ int [] sequencesLength = new int [array .length ];
20+ for (int i = 0 ; i < array .length ; i ++) {
21+ sequencesLength [i ] = 1 ;
22+ for (int j = 0 ; j < i ; j ++) {
23+ if (sequencesLength [j ] + 1 > sequencesLength [i ] && array [i ] % array [j ] == 0 ) {
24+ sequencesLength [i ] = sequencesLength [j ] + 1 ;
25+ }
26+ }
27+ largestSubsequenceLength = Integer .max (largestSubsequenceLength , sequencesLength [i ]);
28+ }
29+ return largestSubsequenceLength ;
30+ }
31+
32+ public static void main (String [] args ) {
33+ new Main ().run ();
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments