zoukankan      html  css  js  c++  java
  • 【递归】类循环排列

    输入样例:

    3 2

    输出样例:

    0 0 0

    0 0 1

    0 1 0

    0 1 1

    1 0 0

    1 0 1

    1 1 0

    1 1 1

    Delphi 代码:

    program loop_permutation;
    //类循环排列
    const
    max_n = 10;

    var
    n,m: integer;
    rcd: array[0..max_n] of integer;

    procedure loop_permutation(index: integer);
    var
    i: integer;
    begin
    if index=n then
    begin
    for i := 0 to index - 1 do
    begin
    write(rcd[i]);
    if i<index-1 then
    write(' ')
    else
    writeln;
    end;
    exit;
    end;

    for i := 0 to m-1 do
    begin
    rcd[index] := i;
    loop_permutation(index+1);
    end;
    end;

    begin
    while not SeekEOF do
    begin
    readln(n,m);
    loop_permutation(0);
    end;
    end.

    C++代码:

    //类循环排列

    #include <stdio.h>
    #define MAX_N 10

    int n,m;
    int rcd[MAX_N];

    void loop_permutation(int index)
    {
    int i;
    if (index == n)
    {
    for (i =0; i<n; i++)
    {
    printf("%d", rcd[i]);
    if (i<n-1)
    {
    printf(" ");
    }
    }
    printf("\n");
    return;
    }
    for (i=0; i<m; i++)
    {
    rcd[index] = i;
    loop_permutation(index+1);
    }
    }

    int main()
    {
    while (scanf("%d%d", &n, &m) != EOF)
    {
    loop_permutation(0);
    }
    return 0;
    }




  • 相关阅读:
    类与类之间的关系图
    UML介绍
    数据建模
    状态图
    部署图
    用例图
    业务建模
    时序图
    postgresql 维护手册
    ashx文件的使用(转)
  • 原文地址:https://www.cnblogs.com/wouldguan/p/2435186.html
Copyright © 2011-2022 走看看