当前位置: 首页 > news >正文

做网站该读啥学校互动类网站

做网站该读啥学校,互动类网站,win2012服务器做网站,守游网络推广平台Description 输出给定序列按字典序的 � 组合,按照所有 � 个元素出现与否的 01 标记串 ����−1,...,�1 的字典序输出. 此处01串的字典序指:先输入的数字对应低位&#x…

Description

输出给定序列按字典序的 � 组合,按照所有 � 个元素出现与否的 01 标记串 ����−1,...,�1 的字典序输出.

此处01串的字典序指:先输入的数字对应低位,后输入的数字对应高位,从高位到低位第一个不一样的位为1的字典序靠后.

Input

第一行集合元素个数 1≤�≤10 及子集元素个数 1≤�≤�,第二行 � 个空格隔开的正整数 1≤��≤100.

Output

每组数据输出所有对应的每个组合,每个一行用空格隔开。

Sample

#0
Input

Copy

5 3
3 1 2 4 5
Output

Copy

3 1 2
3 1 4
3 2 4
1 2 4
3 1 5
3 2 5
1 2 5
3 4 5
1 4 5
2 4 5

Hint

样例中:{3,1,4}表示01011——5(0)4(1)2(0)1(1)3(1),{1,2,5}表示10110——5(1)4(0)2(1)1(1)3(0),则{1,2,5}的字典序比{3,1,4}靠后.

题目有点难懂

方法用回溯求组合数然后排序

#include <iostream>
#include <cstring>
#include <queue>
#include <climits>
#include "vector"
#include "set"
#include "string"
#include "cmath"
#include "algorithm"
using namespace std;
int a[15];
int use[15];
int weight[105];
int n,r;
//3 1 2 4 5
//1 1 1 0 0
//1 1 0 1 0
bool cmp(vector<int>v1,vector<int>v2){int s1=0,s2=0;for(int j=n-1;j>=0;j--){if(std::find(v1.begin(), v1.end(),a[j])!=v1.end()){s1=1;}if(std::find(v2.begin(), v2.end(),a[j])!=v2.end()){s2=1;}if(s1!=s2){if(s1==0){return true;}else{return false;}}s1=0,s2=0;}
}
void backtrack(int a[],int n,int r,vector<int>&temp,vector<vector<int>>&ans){if(temp.size()==r){ans.push_back(temp);return;}for(int i=0;i<n;i++){if(use[i]==0&&((!temp.empty()&&weight[a[i]]<weight[temp[temp.size()-1]])||temp.empty())){use[i]=1;temp.push_back(a[i]);backtrack(a,n,r,temp,ans);temp.pop_back();use[i]=0;}}
}
int main()
{while(cin>>n>>r){memset(use,0, sizeof(use));for(int i=0;i<n;i++){cin>>a[i];weight[a[i]]=n-i;}vector<int>temp;vector<vector<int>>ans;backtrack(a,n,r,temp,ans);sort(ans.begin(),ans.end(), cmp);for(int i=0;i<ans.size();i++){for(int j=0;j<r;j++){cout<<ans[i][j]<<" ";}cout<<endl;}cout<<endl;}return 0;
}

http://www.sczhlp.com/news/94768/

相关文章:

  • 网站开发实现的环境苏州优秀网站设计企业
  • 福建省建设工程监理协会网站精品课网站制作
  • 滨州网站建设公司报价wordpress无法超链接
  • 配置win10、linux虚拟机ip
  • 如何建设万网网站宁波网站建设制作订做
  • 购物网站模块例子网站cn和com哪个做站好
  • 好的做网站的公司百度上广告怎么搞上去的
  • discuz 科技网站模板云主机 小型网站
  • 【正则表达式初探】grep 命令避免匹配自身
  • 测试工程师的核心竞争力是什么?绝不是点点点
  • 关于 ECT-OS-JiuHuaShan 框架的终极阐释
  • 河北网站建设公司排名北京到安阳多少公里路
  • 国内网站做国外服务器163企业邮箱怎么申请
  • 域名申请好怎么做网站网站建设通查询
  • 视频网站建设服务沈阳有名的设计公司有哪些
  • 做色流网站在哪买seo描述是什么
  • 南昌市网站备案重庆模板建站哪家好
  • 第9类商标有网站开发开发app软件需要多少费用
  • 厦门网站开发公安宁市建设局网站
  • 淄博网站制作哪家好网页布局有哪些
  • 网站开发众包简历网站推荐
  • 向“光”而行 | 相聚2025 ASML中国日,携手奔赴“芯”辰大海
  • JavaDay3
  • U3D动作游戏开发读书笔记--2.2 编辑器本身的基础知识
  • 恒华大厦做网站公司企业做网站的目的
  • 做旅游信息的网站能赚钱吗网站开发技术教程
  • 网站建设要那些收费项dz门户 WordPress
  • 沧州做网站公司六安网站优化
  • 苏州建设网站电话六安网站制作费用
  • 网站开发用什么语言最多网站做引流