1からNまでの要素に対してAlexanderBogomolnyの順序付けられていない順列アルゴリズムを実装するC++プログラム
これは、1からNまでの要素に対してAlexanderBogomolnyのUnorderedPermutationAlgorithmを実装するためのC++プログラムです
アルゴリズム
Begin function AlexanderBogomolny() to implement the Algorithms Arguments: Val[] = an array N = number of elements taken as input. K = level Body of the function: intialize l = -1 l = l+1 Val[k] = l if (l == N) Call function display(Val, N) else for i = 0 to N-1 if (Val[i] == 0) Call AlexanderBogomolny(Val, N, i) l = l - 1 Val[k] = 0 Endを呼び出します
例
#include<iostream>
#include<iomanip>
using namespace std;
void display(const int *n, const int size) //to display the permutation
{
int i;
if (n != 0) {
for ( i = 0; i < size; i++) {
cout<<setw(4)<<n[i];
}
cout<<"\n";
}
}
void AlexanderBogomolny(int *Val, int N, int k) {
static int l = -1;
int i;
//At start,Assign level to 0.
l = l+1;
Val[k] = l;
if (l == N)
display(Val, N);
else
for (i = 0; i < N; i++)
//Assign values to the array if it is zero.
if (Val[i] == 0)
AlexanderBogomolny(Val, N, i);
//Decrement the level after all possible permutation after that level.
l = l-1;
Val[k] = 0;
}
int main() {
int i, N, cnt = 1;
cout<<"Enter the value to permute first N natural numbers: ";
cin>>N;
int Val[N];
for (i = 0; i < N; i++) {
Val[i] = 0;
cnt *= (i+1);
}
cout<<"\nThe number of permutations possible is: "<<cnt;
cout<<"\n\nPermutation using Alexander Bogomolyn's Algorithms \n";
AlexanderBogomolny(Val, N, 0);
return 0;
} 出力
Enter the value to permute first N natural numbers: 5 The number of permutations possible is: 120 Permutation using Alexander Bogomolyn's Algorithms 1 2 3 4 5 1 2 3 5 4 1 2 4 3 5 1 2 5 3 4 1 2 4 5 3 1 2 5 4 3 1 3 2 4 5 1 3 2 5 4 1 4 2 3 5 1 5 2 3 4 1 4 2 5 3 1 5 2 4 3 1 3 4 2 5 1 3 5 2 4 1 4 3 2 5 1 5 3 2 4 1 4 5 2 3 1 5 4 2 3 1 3 4 5 2 1 3 5 4 2 1 4 3 5 2 1 5 3 4 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スクは、最適なページ置換アルゴリズムを使用してメモリブロックをページに割り当てるときのように、ヒットとミスの数を見つけることです。 最適なページ置換アルゴリズムとは何ですか? 最適なページ置換アルゴリズムは、ページ置換アルゴリズムです。ページ置換アルゴリズムは、どのメモリページを置換するかを決定するアルゴリズムです。最適なページ置換では、実際には実装できませんが、近い将来に参照されないページを置換しますが、これは最適であり、ミスが最小限であり、最適です。 例を使って図式的に説明して理解しましょう。 ここで、1、2、3を割り当てた後、メモリが
-
ヴィジュネル暗号を実装するためのC++プログラム
Vigenere Cipherは、アルファベットのテキストを暗号化する一種の多表式置換方法です。 この方法での暗号化と復号化には、AからZまでのアルファベットが26行で書き込まれるVigenereCipherTableが使用されます。 暗号化 キー: ようこそ メッセージ: Thisistutorialspoint ここでは、指定されたキーの長さが元のメッセージの長さと等しくなるまで、そのキーを繰り返してキーを取得する必要があります。 暗号化の場合は、メッセージの最初の文字とキー(TとW)を取得します。V行とW列が一致するVigenere Cipher Tableのアルファベ