Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define MAX 50
- using namespace std;
- //permutaciq bez povtoreniq
- int n, used[MAX], pos[MAX];
- void print();
- void permute(int node);
- int main(){
- cin >> n;
- permute(1);
- return 0;
- }
- void print(){
- for(int i = 1; i <=n; i++)
- cout << pos[i] << " ";
- cout << endl;
- }
- void permute(int node){
- if(node == n+1){
- print();
- return;
- }
- for(int i = 1; i <= n; i++)
- if(!used[i]){
- used[i] = 1;
- pos[node] = i;
- permute(node+1);
- used[i] = 0;
- }
- }
- //lesnoto
- char b[5] = { ‘1’, ‘2’, ‘3’ };
- cout<<b;
- while (next_permutation(b, b + 3))
- cout<<b;
- //variacii bez povtoreniq
- int n, p[MAX], k, used[MAX];
- void print() {
- for (int i = 1; i <= k; i++)
- cout << p[i] << " ";
- cout << endl;
- }
- void variation(int node) {
- if (node == k+1) {
- print();
- return;
- }
- for(int i = 1; i <= n; i++)
- if(!used[i]) {
- used[i] = 1;
- p[node] = i;
- variation(node+1);
- used[i] = 0;
- }
- }
- int main() {
- cin >> n >> k;
- variation(1);
- return 0;
- }
- //komvinaciqq bez povtoreniq
- #include <iostream>
- #define MAX 50
- using namespace std;
- int n, k, p[MAX];
- void print() {
- for(int i = 1; i <= k; i++)
- cout << p[i] << " ";
- cout << endl;
- }
- void comb(int node) {
- if(node == k+1) {
- print();
- return;
- }
- for ( int i = p[node-1]+1; i <= n – k + node; i++) {
- p[node] = i;
- comb(node+1);
- }
- }
- int main() {
- cin >> n >> k;
- comb(1);
- system("pause");
- return 0;
- }
- //kombinacii s povtoreniq
- int main() {
- cin >> n >> k;
- p[0]=1; //tozi red
- comb(1);
- system("pause");
- return 0;
- }
- void comb (int node) {
- if (node == k+1) {
- print();
- return;
- }
- for ( int i = p[node-1]; i <= n – k + node; i++) {
- p[node] = i;
- comb(node+1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement