Advertisement
Guest User

nasko

a guest
Dec 14th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <iostream>
  2. #define MAX 50
  3. using namespace std;
  4.  
  5. //permutaciq bez povtoreniq
  6. int n, used[MAX], pos[MAX];
  7.  
  8. void print();
  9. void permute(int node);
  10.  
  11. int main(){
  12. cin >> n;
  13. permute(1);
  14. return 0;
  15. }
  16.  
  17. void print(){
  18. for(int i = 1; i <=n; i++)
  19. cout << pos[i] << " ";
  20. cout << endl;
  21. }
  22.  
  23. void permute(int node){
  24.  
  25. if(node == n+1){
  26. print();
  27. return;
  28. }
  29.  
  30. for(int i = 1; i <= n; i++)
  31. if(!used[i]){
  32. used[i] = 1;
  33. pos[node] = i;
  34. permute(node+1);
  35. used[i] = 0;
  36. }
  37. }
  38. //lesnoto
  39. char b[5] = { ‘1’, ‘2’, ‘3’ };
  40. cout<<b;
  41. while (next_permutation(b, b + 3))
  42. cout<<b;
  43.  
  44. //variacii bez povtoreniq
  45. int n, p[MAX], k, used[MAX];
  46.  
  47. void print() {
  48. for (int i = 1; i <= k; i++)
  49. cout << p[i] << " ";
  50. cout << endl;
  51. }
  52.  
  53. void variation(int node) {
  54. if (node == k+1) {
  55. print();
  56. return;
  57. }
  58. for(int i = 1; i <= n; i++)
  59. if(!used[i]) {
  60. used[i] = 1;
  61. p[node] = i;
  62. variation(node+1);
  63. used[i] = 0;
  64. }
  65. }
  66. int main() {
  67. cin >> n >> k;
  68. variation(1);
  69.  
  70. return 0;
  71. }
  72.  
  73.  
  74. //komvinaciqq bez povtoreniq
  75. #include <iostream>
  76. #define MAX 50
  77. using namespace std;
  78.  
  79. int n, k, p[MAX];
  80.  
  81. void print() {
  82. for(int i = 1; i <= k; i++)
  83. cout << p[i] << " ";
  84. cout << endl;
  85. }
  86. void comb(int node) {
  87. if(node == k+1) {
  88. print();
  89. return;
  90. }
  91. for ( int i = p[node-1]+1; i <= n – k + node; i++) {
  92. p[node] = i;
  93. comb(node+1);
  94. }
  95. }
  96. int main() {
  97. cin >> n >> k;
  98. comb(1);
  99. system("pause");
  100. return 0;
  101. }
  102. //kombinacii s povtoreniq
  103. int main() {
  104. cin >> n >> k;
  105. p[0]=1; //tozi red
  106. comb(1);
  107. system("pause");
  108. return 0;
  109. }
  110. void comb (int node) {
  111. if (node == k+1) {
  112. print();
  113. return;
  114. }
  115. for ( int i = p[node-1]; i <= n – k + node; i++) {
  116. p[node] = i;
  117. comb(node+1);
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement