题意:给出数组的长度n,给出h,表示这个数组里面含有h个1,求其所有的排列

用next_permutation就可以了

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include <cmath>
 5 #include<stack>
 6 #include<vector>
 7 #include<map>
 8 #include<set>
 9 #include<queue>
10 #include<algorithm>
11 using namespace std;
12
13 #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
14
15 typedef long long LL;
16 const int INF = (1<<30)-1;
17 const int mod=1000000007;
18 const int maxn=100005;
19
20 int p[maxn];
21
22 int main(){
23     int T;
24     scanf("%d",&T);
25     while(T--){
26
27         int n,h;
28         scanf("%d %d",&n,&h);
29
30         for(int i=0;i<n;i++){
31             if(i<h) p[i]=1;
32             else p[i]=0;
33         }
34
35         sort(p,p+n);
36
37         do{
38             for(int i=0;i<n;i++) printf("%d",p[i]);
39             printf("\n");
40         }while(next_permutation(p,p+n));
41
42         if(T)  printf("\n");
43     }
44     return 0;
45 }

View Code

转载于:https://www.cnblogs.com/wuyuewoniu/p/4474096.html

UVa 729 The Hamming Distance Problem【枚举排列】相关推荐

  1. 简单枚举 / 枚举排列

    本文参考<算法竞赛入门经典>第七章<暴力枚举法>,提出的是暴力"列举"出所有可能性并一一试验的方法. 目录 1 简单枚举 2 枚举排列 2.1 生成1~n的 ...

  2. Leetcode 461. Hamming Distance JAVA语言

    The Hamming distance between two integers is the number of positions at which the corresponding bits ...

  3. [LeetCode] 461. Hamming Distance

    The Hamming distance between two integers is the number of positions at which the corresponding bits ...

  4. C++ hamming distance汉明距离算法(附完整源码)

    hamming distance汉明距离的算法 hamming distance汉明距离的算法的完整源码(定义,实现,main函数测试) hamming distance汉明距离的算法的完整源码(定义 ...

  5. LeetCode 461 Hamming Distance(汉明距离)

    Q:The Hamming distance between two integers is the number of positions at which the corresponding bi ...

  6. LeetCode之Hamming Distance

    1.题目 The Hamming distance between two integers is the number of positions at which the corresponding ...

  7. 461. Hamming Distance【数学|位运算】

    2017/3/14 15:23:55 The Hamming distance between two integers is the number of positions at which the ...

  8. LeetCode 461. Hamming Distance

    题目: The Hamming distance between two integers is the number of positions at which the corresponding ...

  9. C#LeetCode刷题之#461-汉明距离​​​​​​​(Hamming Distance)

    问题 两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目. 给出两个整数 x 和 y,计算它们之间的汉明距离. 注意:0 ≤ x, y < 231. 输入: x = 1, y = ...

最新文章

  1. 服务器技术综述(四)
  2. DLINQ *.dbml文件该属于哪一层
  3. RabbitMq的学习(一):VirtualHost
  4. 实操笔记:为 NSQ 配置监控服务的心路历程
  5. Spring里Bean类的运行时小写之谜
  6. 调查显示企业对 Linux 开发人才需求日渐增长
  7. pip install scrapy安装scrapy库出现error: Microsoft Visual C++ 14.0 is required.问题解决
  8. python构建指数平滑预测模型_python/scikit/numpy中r指数平滑状态空间模型的替代方案...
  9. Gradle+IDEA使用说明
  10. python json文件太大_python - python json.dump创建的文件太大 - 堆栈内存溢出
  11. 指针写字符比较c语言,利用指针进行字符串大小比较出现的问题
  12. 三元运算符 python_Python三元运算符
  13. 构建插件式的应用程序框架(四)----服务容器
  14. LeetCode – Refresh – Exceel Sheet Column Number
  15. [.NET领域驱动设计实战系列]专题十:DDD扩展内容:全面剖析CQRS模式实现
  16. 转速恒压频比交流变频调速系统Simulink仿真,可观察到电压频率的变比情况以及电动机的转速波形。
  17. spring boot整合第三方微信开发工具 weixin-java-miniapp 实现小程序微信登录
  18. QCA wlan driver load
  19. 如何使用pyinstaller将Python的代码打包
  20. yolov5 6.1官方模板TensorRT加速保姆级图文教程

热门文章

  1. 免费的网络推广教大家新站点前期优化如何进行?
  2. linux端口转发到windows,Linux及Windows基于工具的端口转发
  3. 虚拟化服务器端口用万兆,万兆以太网部署需要注意的方面有哪些
  4. 全字库说文解字字体_整理了10款免费商用中文字体,超好用
  5. python处理csv中的缺失值_Python中重复值、缺失值、空格值处理
  6. 开发日记-20190515 关键词 汇编语言(八) MVVM
  7. 从pfx里面 解析出公私钥
  8. Django、Flask、Tornado的比较
  9. 关系型数据库与NOSQL
  10. oracle 性能优化--索引总结