博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
擅长排列的小明
阅读量:6925 次
发布时间:2019-06-27

本文共 1241 字,大约阅读时间需要 4 分钟。

擅长排列的小明

时间限制:
1000 ms  |  内存限制:65535 KB
难度:
4
描述
小明十分聪明,而且十分擅长排列计算。比如给小明一个数字5,他能立刻给出1-5按字典序的全排列,如果你想为难他,在这5个数字中选出几个数字让他继续全排列,那么你就错了,他同样的很擅长。现在需要你写一个程序来验证擅长排列的小明到底对不对。
输入
第一行输入整数N(1<N<10)表示多少组测试数据,
每组测试数据第一行两个整数 n m (1<n<9,0<m<=n)
输出
在1-n中选取m个字符进行全排列,按字典序全部输出,每种排列占一行,每组数据间不需分界。如样例
样例输入
23 14 2
样例输出
123121314212324313234414243

题解:没事水的一道题,编译错误,没有pthread的头文件。。。。

代码

#include 
#include
#include
#include
#include
#include
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://eocjl.baihongyu.com/

你可能感兴趣的文章
专访阿里云MVP黄胜蓝:90 后 CTO花了6年,改变了你日常生活里的这件事
查看>>
2017-11-17 为clang添加中文关键字
查看>>
Intro.js 分步向导插件使用方法
查看>>
js对象的两种写法
查看>>
PostgreSQL 10.1 手册_部分 II. SQL 语言_第 7 章 查询_7.8. WITH查询(公共表表达式)...
查看>>
BOSE打造新型AR眼镜Frames,可通过声音来实现身临其境的音频体验
查看>>
提速 10%,V8 引擎推出全新 Liftoff 基线编译器
查看>>
控件篇
查看>>
PostgreSQL 10.1 手册_部分 III. 服务器管理_第 21 章 数据库角色_21.5. 默认角色
查看>>
HTTP响应状态码参考
查看>>
[UWP]新控件ColorPicker
查看>>
巧用fastjson自定义序列化类实现字段的转换
查看>>
基于 ANSIBLE 自动化运维实践
查看>>
MYSQL调优常用的方法
查看>>
PHP 扫码识别信息
查看>>
销毁其他进程的弹窗
查看>>
基于java的分布式爬虫
查看>>
【解决错误码为0xC8000222的 .NET Framework 4 安装失败问题】
查看>>
在Linux的sqlplus中不能使用vi时的解决方法
查看>>
【framework】spring3-mvc-开篇
查看>>