NYOJ 32 组合数
来源:互联网 发布:jquery 二维数组 push 编辑:程序博客网 时间:2024/06/05 22:45
组合数
时间限制:3000 ms | 内存限制:65535 KB
难度:3
- 描述
- 找出从自然数1、2、... 、n(0<n<10)中任取r(0<r<=n)个数的所有组合。
- 输入
- 输入n、r。
- 输出
- 按特定顺序输出所有组合。
特定顺序:每一个组合中的值从大到小排列,组合之间按逆字典序排列。 - 样例输入
5 3
- 样例输出
543542541532531521432431421321
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> #include<vector> #include<stack> #include<bitset> #include<cstdlib> #include<cmath> #include<set> #include<list> #include<deque> #include<map> #include<queue> using namespace std;int n, r;int a[15];void dfs(int num,int count){//简单深搜,我们每一级的值是逆字典序查找的,注意里面含有两个判定条件,i>0以及count==r。if (count == r) {for (int i = 0; i < count; i++)cout << a[i];cout << endl;return;}for (int i = num; i > 0; i--) {a[count] = i;dfs(i-1, count+1);}}int main() {cin >> n >> r;dfs(n, 0);return 0; }
阅读全文
0 0
- NYOJ 32 组合数
- NYOJ-组合数-32
- nyoj 32-组合数
- NYOJ,32,组合数
- nyoj 32 组合数
- nyoj-32-组合数
- nyoj 32 组合数
- NYOJ-32组合数
- nyoj 32 组合数
- NYOJ 32 组合数
- nyoj--32--组合数
- NYOJ 32 组合数
- NYOJ-组合数-32
- NYOJ-32 组合数
- NYOJ 32组合数
- NYOJ 32 组合数
- nyoj 32 组合数
- nyoj 32 组合数
- 基于知识图谱的电影自动问答系统(二)自动问答实现
- dict() 和collections.defaultdict的区别
- eclipse插件安装时因为是外网的原因很不稳定,时不时会出现Unable to read repository at http://*。jar Read timed out
- rsync小记
- AndroidStudio集成Git-1配置.ssh
- NYOJ 32 组合数
- 登录,注册,修改密码,倒计时工具类编写
- 作为SEO你应该知道蜘蛛的HTTP状态码
- 详解Spring整合Quartz实现动态定时任务
- Windows 安装opencv 使用pip安装简单的方法
- java12周第一题
- 兼容iphoneX
- OpenStack+Ceph+热迁移+++七、实现热迁移
- FreeMarker入门案例