erlang版
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(perm). | |
-export([rperm/1]). | |
rperm(List) -> rperm(List,0). | |
rperm(List,C) when C =:= length(List) -> [[]]; | |
rperm(List,C) -> [[Head|Tail] || Head <- List, Tail <- rperm(List, C+1)]. |
Java版
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RepeatedPermutation { | |
static int N; | |
static char[] c; | |
static int[] p; | |
public static void main(String[] args) { | |
c = args[0].toCharArray(); | |
N = c.length; | |
p = new int[N]; | |
for (int i = 0; i < N; i++) { | |
calc(0, i); | |
} | |
} | |
static void calc(int i, int j) { | |
p[i] = j; | |
if (i == N - 1) { | |
for (int n = 0; n < N; n++) { | |
System.out.print(c[p[n]]); | |
} | |
System.out.println(); | |
} | |
if (i < N - 1) { | |
i++; | |
for (int k = 0; k < N; k++) { | |
calc(i, k); | |
} | |
} | |
} | |
} |
0 件のコメント:
コメントを投稿