UVa 729 The Hamming Distance Problem【枚举排列】
题意:给出数组的长度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 简单枚举 2 枚举排列 2.1 生成1~n的 ...
- Leetcode 461. Hamming Distance JAVA语言
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- [LeetCode] 461. Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- C++ hamming distance汉明距离算法(附完整源码)
hamming distance汉明距离的算法 hamming distance汉明距离的算法的完整源码(定义,实现,main函数测试) hamming distance汉明距离的算法的完整源码(定义 ...
- LeetCode 461 Hamming Distance(汉明距离)
Q:The Hamming distance between two integers is the number of positions at which the corresponding bi ...
- LeetCode之Hamming Distance
1.题目 The Hamming distance between two integers is the number of positions at which the corresponding ...
- 461. Hamming Distance【数学|位运算】
2017/3/14 15:23:55 The Hamming distance between two integers is the number of positions at which the ...
- LeetCode 461. Hamming Distance
题目: The Hamming distance between two integers is the number of positions at which the corresponding ...
- C#LeetCode刷题之#461-汉明距离(Hamming Distance)
问题 两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目. 给出两个整数 x 和 y,计算它们之间的汉明距离. 注意:0 ≤ x, y < 231. 输入: x = 1, y = ...
最新文章
- 服务器技术综述(四)
- DLINQ *.dbml文件该属于哪一层
- RabbitMq的学习(一):VirtualHost
- 实操笔记:为 NSQ 配置监控服务的心路历程
- Spring里Bean类的运行时小写之谜
- 调查显示企业对 Linux 开发人才需求日渐增长
- pip install scrapy安装scrapy库出现error: Microsoft Visual C++ 14.0 is required.问题解决
- python构建指数平滑预测模型_python/scikit/numpy中r指数平滑状态空间模型的替代方案...
- Gradle+IDEA使用说明
- python json文件太大_python - python json.dump创建的文件太大 - 堆栈内存溢出
- 指针写字符比较c语言,利用指针进行字符串大小比较出现的问题
- 三元运算符 python_Python三元运算符
- 构建插件式的应用程序框架(四)----服务容器
- LeetCode – Refresh – Exceel Sheet Column Number
- [.NET领域驱动设计实战系列]专题十:DDD扩展内容:全面剖析CQRS模式实现
- 转速恒压频比交流变频调速系统Simulink仿真,可观察到电压频率的变比情况以及电动机的转速波形。
- spring boot整合第三方微信开发工具 weixin-java-miniapp 实现小程序微信登录
- QCA wlan driver load
- 如何使用pyinstaller将Python的代码打包
- yolov5 6.1官方模板TensorRT加速保姆级图文教程