【位运算+暴力】Codeforces Beta Round #86 (Div. 2 Only) B
来源:互联网 发布:php模板引擎有哪些 编辑:程序博客网 时间:2024/05/29 16:43
本想用图染色的,后来研究了一下才知道这个想法很傻很天真,因为Welch Powell 算法只能求出最小用几种色,不能求出最大有哪几个共存点!
还有,再一次被for里面的i坑了,i里有i,结果查了半天才知道这个诡异的家伙
复杂度:O((1<<n)*n^2),最坏也是65536*256=16777216,2s肯定可以跑完,而且cf的服务器很强大
#include <map>#include <set>#include <list>#include <queue>#include <deque>#include <stack>#include <string>#include <time.h>#include <cstdio>#include <math.h>#include <iomanip>#include <cstdlib>#include <limits.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;#define LL long long#define PI acos(-1.0)#define N 20#define MAX INT_MAX#define MIN INT_MIN#define eps 1e-8#define FRE freopen("a.txt","r",stdin)int n,m;string str[N];int g[N][N];int id[N];vector<string> v;int get(string a){ int i; for(i=0;i<n;i++){ if(str[i]==a) return i; }}int main(){ //FRE; while(scanf("%d%d",&n,&m)!=EOF){ int i,j,k; for(i=0;i<n;i++){ cin>>str[i]; } memset(g,0,sizeof(g)); while(m--){ string a,b; cin>>a>>b; int s=get(a); int t=get(b); g[s][t]=g[t][s]=1; } int maxm=0; for(i=0;i<(1<<n);i++){ int cnt=0; int t=0; memset(id,0,sizeof(id)); int ii=i; while(ii){ if(ii&1){ t++; id[cnt]=1; } ii>>=1; cnt++; } bool flag=1; for(j=0;j<n;j++){ for(k=0;k<n;k++){ if(id[j]==1 && id[k]==1 && g[j][k]){ flag=0; break; } } if(!flag)break; } if(flag){ if(t>maxm){ v.clear(); maxm=t; for(j=0;j<n;j++){ if(id[j]) v.push_back(str[j]); } } } } sort(v.begin(),v.end()); printf("%d\n",maxm); for(i=0;i<maxm;i++) cout<<v[i]<<endl; } return 0;}
- 【位运算+暴力】Codeforces Beta Round #86 (Div. 2 Only) B
- Codeforces Beta Round #86 (Div. 2 Only) B PFAST Inc.
- Codeforces Beta Round #86 (Div. 2 Only)
- Codeforces Beta Round #93 (Div. 2 Only)——B
- Codeforces Beta Round #91 (Div. 2 Only)——B
- Codeforces Beta Round #18 (Div. 2 Only)——B
- Codeforces Beta Round #92 (Div. 2 Only) B. Permutations
- Codeforces Beta Round #22 (Div. 2 Only)-B. Bargaining Table
- Codeforces Beta Round #9 (Div. 2 Only):B
- Codeforces Beta Round #80 (Div. 2 Only)
- Codeforces Beta Round #83 (Div. 2 Only)
- Codeforces Beta Round #93 (Div. 2 Only)
- Codeforces Beta Round #4 (Div. 2 Only)
- Codeforces Beta Round #6 (Div. 2 Only)
- Codeforces Beta Round #9 (Div. 2 Only)
- Codeforces Beta Round #4 (Div. 2 Only)
- Codeforces Beta Round #4 (Div. 2 Only)
- Codeforces Beta Round #6 (Div. 2 Only)
- 通过修改HOSTS方式访问GAE
- 计算WEB服务器负载量的两种方法
- Jetty 架构
- CFileDialog的详解
- Servlet字符编码过滤器
- 【位运算+暴力】Codeforces Beta Round #86 (Div. 2 Only) B
- 李开复:给父母的四个建议
- 谷歌去年耗电23亿度 相当21万家庭用电量
- 学习java,领悟到的编程思想
- ASP.net Repeater控件隐藏列 自写一个测试
- CImage类
- Class.forName 介绍
- 在ubuntu下删除U盘分区及多分区格式化
- 基于jQuery与PHP实现Ajax长轮询(LongPoll)