(排列数)输入两个正整数n,m(1<n<20, 1<m<n),在1~n中任取m个数,按字典序从小到大输出所有这样的排列。例如: 输入:3 2 输出:1 2 1 3 2 1 2 3 3 1 3 2 #include <iostream> #include <cstring> using namespace std; const int SIZE = 25; bool used[SIZE]; int data[SIZE]; int n, m, i, j, k; bool flag; int main( ) { cin >> n >> m; memset(used, false, sizeof(used)); for (i = 1; i <= m; i++) { data[i] = i; used[i] = true; } flag = true; while (flag) { for (i = 1; i <= m – 1; i++) cout << data[i] << " "; cout << data[m] << endl; flag = 1 ; for (i = m; i >= 1; i–) { 2 ; for (j = data[i] + 1; j <= n; j++) if (!used[j]) { used[j] = true; data[i] = 3 ; flag = true; break; } if (flag) { for (k = i + 1; k <= m; k++) for (j = 1; j <= 4 ; j++) if (!used[j]) { data[k] = j; used[j] = true; break; } 5 ; } } } return 0; }
区块链毕设网qklbishe.com为您提供问题的解答
(排列数)输入两个正整数n,m(1<n<20, 1<m<n),在1~n中任取m个数,按字典序从小到大输出所有这样的排列。例如:
输入:3 2
输出:1 2
1 3
2 1
2 3
3 1
3 2
#include <iostream> #include <cstring> using namespace std; const int SIZE = 25; bool used[SIZE]; int data[SIZE]; int n, m, i, j, k; bool flag; int main( ) { cin >> n >> m; memset(used, false, sizeof(used)); for (i = 1; i <= m; i++) { data[i] = i; used[i] = true; } flag = true; while (flag) { for (i = 1; i <= m - 1; i++) cout << data[i] << " "; cout << data[m] << endl; flag = 1; for (i = m; i >= 1; i--) { 2; for (j = data[i] + 1; j <= n; j++) if (!used[j]) { used[j] = true; data[i] = 3; flag = true; break; } if (flag) { for (k = i + 1; k <= m; k++) for (j = 1; j <= 4; j++) if (!used[j]) { data[k] = j; used[j] = true; break; } 5; } } } return 0; }
以上就是关于问题(排列数)输入两个正整数n,m(1<n<20, 1<m<n),在1~n中任取m个数,按字典序从小到大输出所有这样的排列。例如:
输入:3 2
输出:1 2
1 3
2 1
2 3
3 1
3 2
#include <iostream> #include <cstring> using namespace std; const int SIZE = 25; bool used[SIZE]; int data[SIZE]; int n, m, i, j, k; bool flag; int main( ) { cin >> n >> m; memset(used, false, sizeof(used)); for (i = 1; i <= m; i++) { data[i] = i; used[i] = true; } flag = true; while (flag) { for (i = 1; i <= m – 1; i++) cout << data[i] << " "; cout << data[m] << endl; flag = 1 ; for (i = m; i >= 1; i–) { 2 ; for (j = data[i] + 1; j <= n; j++) if (!used[j]) { used[j] = true; data[i] = 3 ; flag = true; break; } if (flag) { for (k = i + 1; k <= m; k++) for (j = 1; j <= 4 ; j++) if (!used[j]) { data[k] = j; used[j] = true; break; } 5 ; } } } return 0; }的答案
欢迎关注区块链毕设网-
专业区块链毕业设计成品源码,定制。
区块链NFT链游项目方科学家脚本开发培训
从业7年-专注一级市场
微信:btc9767
TELEGRAM :https://t.me/btcok9
具体资料介绍
web3的一级市场千万收益的逻辑
进群点我
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台-javagopython毕设 » (排列数)输入两个正整数n,m(1<n<20, 1<m<n),在1~n中任取m个数,按字典序从小到大输出所有这样的排列。例如:
输入:3 2
输出:1 2
1 3
2 1
2 3
3 1
3 2
#include <iostream> #include <cstring> using namespace std; const int SIZE = 25; bool used[SIZE]; int data[SIZE]; int n, m, i, j, k; bool flag; int main( ) { cin >> n >> m; memset(used, false, sizeof(used)); for (i = 1; i <= m; i++) { data[i] = i; used[i] = true; } flag = true; while (flag) { for (i = 1; i <= m – 1; i++) cout << data[i] << " "; cout << data[m] << endl; flag = 1 ; for (i = m; i >= 1; i–) { 2 ; for (j = data[i] + 1; j <= n; j++) if (!used[j]) { used[j] = true; data[i] = 3 ; flag = true; break; } if (flag) { for (k = i + 1; k <= m; k++) for (j = 1; j <= 4 ; j++) if (!used[j]) { data[k] = j; used[j] = true; break; } 5 ; } } } return 0; }
微信:btc9767
TELEGRAM :https://t.me/btcok9
具体资料介绍
web3的一级市场千万收益的逻辑
进群点我
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台-javagopython毕设 » (排列数)输入两个正整数n,m(1<n<20, 1<m<n),在1~n中任取m个数,按字典序从小到大输出所有这样的排列。例如:
输入:3 2
输出:1 2
1 3
2 1
2 3
3 1
3 2
#include <iostream> #include <cstring> using namespace std; const int SIZE = 25; bool used[SIZE]; int data[SIZE]; int n, m, i, j, k; bool flag; int main( ) { cin >> n >> m; memset(used, false, sizeof(used)); for (i = 1; i <= m; i++) { data[i] = i; used[i] = true; } flag = true; while (flag) { for (i = 1; i <= m – 1; i++) cout << data[i] << " "; cout << data[m] << endl; flag = 1 ; for (i = m; i >= 1; i–) { 2 ; for (j = data[i] + 1; j <= n; j++) if (!used[j]) { used[j] = true; data[i] = 3 ; flag = true; break; } if (flag) { for (k = i + 1; k <= m; k++) for (j = 1; j <= 4 ; j++) if (!used[j]) { data[k] = j; used[j] = true; break; } 5 ; } } } return 0; }
进群点我
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台-javagopython毕设 » (排列数)输入两个正整数n,m(1<n<20, 1<m<n),在1~n中任取m个数,按字典序从小到大输出所有这样的排列。例如:
输入:3 2
输出:1 2
1 3
2 1
2 3
3 1
3 2
#include <iostream> #include <cstring> using namespace std; const int SIZE = 25; bool used[SIZE]; int data[SIZE]; int n, m, i, j, k; bool flag; int main( ) { cin >> n >> m; memset(used, false, sizeof(used)); for (i = 1; i <= m; i++) { data[i] = i; used[i] = true; } flag = true; while (flag) { for (i = 1; i <= m – 1; i++) cout << data[i] << " "; cout << data[m] << endl; flag = 1 ; for (i = m; i >= 1; i–) { 2 ; for (j = data[i] + 1; j <= n; j++) if (!used[j]) { used[j] = true; data[i] = 3 ; flag = true; break; } if (flag) { for (k = i + 1; k <= m; k++) for (j = 1; j <= 4 ; j++) if (!used[j]) { data[k] = j; used[j] = true; break; } 5 ; } } } return 0; }
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台-javagopython毕设 » (排列数)输入两个正整数n,m(1<n<20, 1<m<n),在1~n中任取m个数,按字典序从小到大输出所有这样的排列。例如: 输入:3 2 输出:1 2 1 3 2 1 2 3 3 1 3 2 #include <iostream> #include <cstring> using namespace std; const int SIZE = 25; bool used[SIZE]; int data[SIZE]; int n, m, i, j, k; bool flag; int main( ) { cin >> n >> m; memset(used, false, sizeof(used)); for (i = 1; i <= m; i++) { data[i] = i; used[i] = true; } flag = true; while (flag) { for (i = 1; i <= m – 1; i++) cout << data[i] << " "; cout << data[m] << endl; flag = 1 ; for (i = m; i >= 1; i–) { 2 ; for (j = data[i] + 1; j <= n; j++) if (!used[j]) { used[j] = true; data[i] = 3 ; flag = true; break; } if (flag) { for (k = i + 1; k <= m; k++) for (j = 1; j <= 4 ; j++) if (!used[j]) { data[k] = j; used[j] = true; break; } 5 ; } } } return 0; }