标签:
2 3 1 4 2
1 2 3 12 13 14 21 23 24 31 32 34 41 42 43
题解:没事水的一道题,编译错误,没有pthread的头文件。。。。
代码
#include <iostream> #include <pthread.h> #include <algorithm> #include <cstdio> #include <queue> #include <cstring> using namespace std; int ans[10]; int vis[10]; struct work_arg{ int n, m; work_arg(int n, int m){ this->n = n; this->m = m; } work_arg(){ } }; void dfs(int i, int n, int m); void *work(void* arg){ work_arg* warg = (work_arg *)arg; int n = warg->n, m = warg->m; memset(vis, 0, sizeof(vis)); dfs(0, n, m); } void dfs(int i, int n, int m){ if(i == m){ for(int p = 0; p < m; p++){ //if(p)printf(" "); printf("%d", ans[p]); } puts(" "); return; } for(int p = 1; p <= n; p++){ if(vis[p])continue; vis[p] = 1; ans[i] = p; dfs(i + 1, n, m); vis[p] = 0; } } int main(){ pthread_t pth; int T; scanf("%d", &T); while(T--){ int m, n; scanf("%d%d", &n, &m); work_arg arg(n, m); pthread_create(&pth, NULL, work, (void *)&arg); pthread_join(pth, NULL); } return 0; }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/5858053.html