1 1
2 2
3 1 2
4 3
5 1 3
6 2 3
7 1 2 3
8 4
9 1 4
10 2 4
11 1 2 4
12 3 4
13 1 3 4
14 2 3 4
15 1 2 3 4
16 5
17 1 5
18 2 5
19 1 2 5
20 3 5
21 1 3 5
22 2 3 5
23 1 2 3 5
24 4 5
25 1 4 5
26 2 4 5
27 1 2 4 5
28 3 4 5
29 1 3 4 5
30 2 3 4 5
31 1 2 3 4 5
32 6
33 1 6
34 2 6
35 1 2 6
36 3 6
37 1 3 6
38 2 3 6
39 1 2 3 6
40 4 6
41 1 4 6
42 2 4 6
43 1 2 4 6
44 3 4 6
45 1 3 4 6
46 2 3 4 6
47 1 2 3 4 6
48 5 6
49 1 5 6
50 2 5 6
51 1 2 5 6
52 3 5 6
53 1 3 5 6
54 2 3 5 6
55 1 2 3 5 6
56 4 5 6
57 1 4 5 6
58 2 4 5 6
59 1 2 4 5 6
60 3 4 5 6
61 1 3 4 5 6
62 2 3 4 5 6
63 1 2 3 4 5 6
64 7
65 1 7
66 2 7
67 1 2 7
68 3 7
69 1 3 7
70 2 3 7前面的是序号 现在要通过后面的几个数值来找到前面的序号- -
不过通过序号来找后面的数值这样正着推我也不会- -更别说反推了。。
求思路 。。想了好久还是想不出。。
2 2
3 1 2
4 3
5 1 3
6 2 3
7 1 2 3
8 4
9 1 4
10 2 4
11 1 2 4
12 3 4
13 1 3 4
14 2 3 4
15 1 2 3 4
16 5
17 1 5
18 2 5
19 1 2 5
20 3 5
21 1 3 5
22 2 3 5
23 1 2 3 5
24 4 5
25 1 4 5
26 2 4 5
27 1 2 4 5
28 3 4 5
29 1 3 4 5
30 2 3 4 5
31 1 2 3 4 5
32 6
33 1 6
34 2 6
35 1 2 6
36 3 6
37 1 3 6
38 2 3 6
39 1 2 3 6
40 4 6
41 1 4 6
42 2 4 6
43 1 2 4 6
44 3 4 6
45 1 3 4 6
46 2 3 4 6
47 1 2 3 4 6
48 5 6
49 1 5 6
50 2 5 6
51 1 2 5 6
52 3 5 6
53 1 3 5 6
54 2 3 5 6
55 1 2 3 5 6
56 4 5 6
57 1 4 5 6
58 2 4 5 6
59 1 2 4 5 6
60 3 4 5 6
61 1 3 4 5 6
62 2 3 4 5 6
63 1 2 3 4 5 6
64 7
65 1 7
66 2 7
67 1 2 7
68 3 7
69 1 3 7
70 2 3 7前面的是序号 现在要通过后面的几个数值来找到前面的序号- -
不过通过序号来找后面的数值这样正着推我也不会- -更别说反推了。。
求思路 。。想了好久还是想不出。。
8 4
9 1 4
10 2 4
11 1 2 4
12 3 4
13 1 3 4
14 2 3 4
15 1 2 3 4这个生成貌似容易,做一个递归就可以生成了.规律就是:
将这一串再传到参数中,判断第一位之前是不是还有比它小的,有的话,
public static void test(String str)
{
//取出串的第一个数字
int x = Integer.parseInt(str.substring(0,str.indexOf(" ")));
for(int j=1;j<x;j++)
{
String newStr = j+" "+str;
System.out.println(newStr );
test(newStr)
}
}
public static void main(String[]args)
{
for(int i=1;i<20;i++)
{
System.out.println(i);
test(1+" ");
}
}至于前边的那个序号就不说了
n = (1<<(k[0]-1)) | (1<<(k[1]-1)) | ... | (1<<(k[m]-1))
其中n是前面的数,k[i]对应后面的数,比如
1 = (1<<(1-1)) //n = 1, k[0] = 1
2 = (1<<(2-1)) //n = 1, k[0] = 2
3 = (1<<(1-1)) | (1<<(2-1)) //n = 3, k[0] = 1, k[1] = 2
4 = (1<<(3-1)) //n = 4, k[0] = 3
5 = (1<<(1-1)) | (1<<(3-1)) //n = 5, k[0] = 1, k[1] = 3
6 = (1<<(2-1)) | (1<<(3-1)) //n = 6, k[0] = 2, k[i+1] = 3
7 = (1<<(1-1)) | (1<<(2-1)) | (1<<(3-1)) //n = 7, k[0] = 1, k[1] = 2, k[2] = 3
...
70 = (1<<(2-1)) | (1<<(3-1)) | (1<<(7-1)) //n = 70, k[0] = 2, k[1] = 3, k[2] = 7换句话说,也就是 n = 2(k[0]-1次方) + 2(k[1]-1次方) + ... + 2(k[m]-1次方)
public class TextX {
int index=1;
public void test(String str)
{
//取出串的第一位
int x = Integer.parseInt(str.substring(0,str.indexOf(" ")));
for(int j=1;j<x;j++)
{
String newStr = j+" "+str;
System.out.print("实际位置:"+index++);
System.out.print("测试位置:"+getIndex(newStr));
System.out.println("数据:"+newStr);
test(newStr);
}
}
public static void main(String[] args) {
TextX x = new TextX();
for(int i=1;i< 15;i++)
{
String str = i+" ";
System.out.print("实际位置:"+x.index++);
System.out.print("测试位置:"+x.getIndex(str));
System.out.println("数据:"+str);
x.test(str);
}
}
public int getIndex(String str)
{
String temp[] = str.split(" ");
int result = 0;
for(String num:temp)
{
if(!"".equals(num))
{
result = result + (int)Math.pow(2,Double.parseDouble(num)-1);
}
}
return result;
}
}