思路:

原来string类能sort 和 swap....太强了....

注意:字典序最小输出,因为某个地方写挫了,sort了n发,代码挫。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL; int tol;
map<string,int>id;
map<int,string>xs;
string ss[20],sss[20]; bool ma[20][20]; int main()
{
string t;
string s;
int n,kk;
id.clear();
xs.clear();
tol=0;
cin>>n>>kk;
for(int i=0; i<n; i++)
cin>>sss[i];
sort(sss,sss+n); for(int i=0;i<n;i++)
{
id[sss[i]]=i;
xs[i]=sss[i];
} memset(ma,false,sizeof(ma));
while(kk--)
{
cin>>s>>t;
ma[id[s]][id[t]]=ma[id[t]][id[s]]=true;
} vector<int> k,res;
int ans=0;
for(int i=0; i<(1<<n); i++)
{
k.clear();
for(int j=0; j<n; j++)
{
if(i&(1<<j))
k.push_back(j);
}
int sz=k.size();
bool flag=true;
for(int p=0; p<sz; p++)
for(int q=0; q<sz; q++)
if(ma[k[p]][k[q]])
flag=false;
if(flag&&ans<sz)
{
res.clear();
ans=sz;
for(int p=0; p<sz; p++)
res.push_back(k[p]);
}
} int num=res.size();
printf("%d\n",num);
for(int i=0; i<num; i++)
ss[i]=xs[res[i]]; sort(ss,ss+num);
for(int i=0; i<num; i++)
cout<<ss[i]<<endl;
return 0;
}

最新文章

  1. nodejs学习笔记一
  2. js的类型及调试下的辨识
  3. 深入浅出Mybatis系列(八)---mapper映射文件配置之select、resultMap
  4. 数据结构《17》---- 自动补齐之《二》----Ternary Search Tree
  5. PHP中CURL方法curl_setopt()函数的参数
  6. UOJ #10 pyx的难题
  7. Reading Famous blog to prevent me wasting time on blind wandering
  8. 机器学习实战-边学边读python代码(5)
  9. PHP验证码
  10. RESTful架构
  11. 解决 Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. 的问题
  12. springmvc中url-pattern的大坑
  13. JavaScript高级程序设计16.pdf
  14. Ceph BlueStore 解析:Object IO到磁盘的映射
  15. Windows核心编程&amp;进程
  16. 奖品列表组件【仿swiper】
  17. 前端面试题整理—ajax篇
  18. 高性价比 VPS virtwire Host
  19. Linux配置SSH免登录
  20. Maven的安装与本地仓库的搭建

热门文章

  1. Javascript 模块化编程 --RequireJs
  2. python 正则表达式(一)
  3. jmeter--简单使用
  4. CodeForces - 1C:Ancient Berland Circus (几何)
  5. CodeForces - 1019D(BZOJ3707圈地):Large Triangle (几何,找面积为S的三角形)
  6. ACM学习历程—UESTC 1215 Secrete Master Plan(矩阵旋转)(2015CCPC A)
  7. NOIp2018集训test-10-18 (bike day4)
  8. POJ1958:Strange Towers of Hanoi
  9. asp.net异常处理和错误页配置
  10. MySQL Sending data导致查询很慢的问题详细分析