标签:style blog class code c tar
Input
Output
Sample Input
3 3 1 2 3 1 3 1 3 2 1 10 2 1 2 3 4 5 6 7 8 9 10
Sample Output
3 1 2 1 2 3 1 2 3 4 5 6 7 9 8 10
解题思路:
学会使用next_permutation
具体代码:
#include<iostream> #include<cstring> #include<string> #include<algorithm> #include<stdio.h> using namespace std; int num[1028]; int main() { int t; cin>>t; while(t--) { int n,k; scanf("%d%d", &n, &k); for(int i=0;i<n;i++) scanf("%d", &num [i]); while(k--) next_permutation(num,num+n); printf("%d", num[0]); for (int i = 1; i < n; i++) printf(" %d", num[i]); printf("\n"); } system("pause"); return 0; }
标签:style blog class code c tar
原文地址:http://www.cnblogs.com/baoluqi/p/3734945.html