-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtencent.java
More file actions
69 lines (64 loc) · 1.53 KB
/
tencent.java
File metadata and controls
69 lines (64 loc) · 1.53 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package algorithmtest;
import java.util.Arrays;
import java.util.Scanner;
public class tencent {
static int total=0;
static int L=0;
public static void check(int[]seq,int L)
{
int num=1;
int temp=seq[0];
for(int i=1;i<seq.length;i++)
{
if(seq[i]-temp>=0)
{
num++;
temp=seq[i];
}
}
if(num==L)
{
total++;
System.out.println(Arrays.toString(seq));
}
}
public static void permute(int[]array,int start)
{
if(start==array.length)
{
//total++;
//System.out.println(Arrays.toString(array));
check(array,L);
}
else{
for(int i=start;i<array.length;++i)
{
swap(array,start,i);
permute(array,start+1);
swap(array,start,i);
}
}
}
public static void swap(int[]array,int s,int i)
{
int t=array[s];
array[s]=array[i];
array[i]=t;
}
public static void main(String[] args) {
total=0;
while (true) {
Scanner sc = new Scanner(System.in);
int size=sc.nextInt();
int num=sc.nextInt();
L=num;
int []input=new int[size];
for(int i=0;i<size;i++)
{
input[i]=sc.nextInt();
}
permute(input,0);
System.out.println(total);
}
}
}