您的位置:首页 > 其它

uva729 - The Hamming Distance Problem(Hamming距离问题)

2013-02-15 14:24 411 查看
题意比较简单,简单的让我有点害怕自己犯想当然的毛病

给三个数据   t-测试数据组数, n-字符串的长度, h-字符串中‘1’的个数。(其余的一定是‘0’)

(我用的是STL中的库函数next_permutation())

代码如下:

#include <cstdio>
#include <algorithm>
using namespace std;
int main ()
{
int t, n, h;
char p[20];
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&h);
p
=0;
for(int i = n-1; i >=0; i--)
if(n-i<=h)p[i] = '1';
else p[i] = '0';
do
{
printf("%s\n",p);
}
while(next_permutation(p,p+n));
if(t)puts("");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: