-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPositionalCel.java
More file actions
55 lines (51 loc) · 1.38 KB
/
Copy pathPositionalCel.java
File metadata and controls
55 lines (51 loc) · 1.38 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package AlgorithmTest;
/*
*
* */
import java.util.HashSet;
import java.util.Set;
public class PositionalCel {
public static void main(String[] args) {
int Array []={108,121,9,85,27};
Cel(Array);
}
public static int Cel(int [] Array){
Set<Integer> result=new HashSet<>();
int len=Array.length;
int temp=0;
//问题转化为找一个数组的连续全排列
for (int i=1;i<=len;i++){
temp= CelNum(Array,i);
for (int j=0;j<temp;){
if (j+i-1>len-1){
int Cel=Array[j];
for(int k=j;k<len-1;k++){
Cel=Cel|Array[k];
}
result.add(Cel);
}else{
int Cel=Array[j];
for(int k=j;k<=j+i-1;k++){
Cel=Cel|Array[k];
}
result.add(Cel);
j++;
}
}
}
System.out.println(result);
return result.size();
}
public static int CelNum(int [] Array,int len){
int result=0;
int length=Array.length;
for (int i=0;i<length;i++) {
if (i + len <= length) {
result++;
} else {
break;
}
}
return result;
}
}