[cpp] #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> //Accepted 168K 454MS C++ using namespace std; int num[1024+10]; int main() { int T, n; int p; scanf("%d", &T); while(T--) { scanf("%d%d", &n, &p); for(int i = 0; i < n; i++) { scanf("%d", &num[i]); } www.2cto.com while(p--) { if(next_permutation(num, num+n) == 0) { sort(num, num+n); } www.2cto.com } for(int i = 0; i < n-1; i++) { printf("%d ", num[i]); } printf("%d\n", num[n-1]); } return 0; } http://poj.org/problem?id=1833