| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:果然是弱数据……水水的写了个AC了,但是discussion里的一组数据过不了……In Reply To:果然是弱数据……水水的写了个AC了,但是discussion里的一组数据过不了…… Posted by:caiminf at 2015-10-30 16:26:39 表示我的爆搜可以过 #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #define MAXN 36 using namespace std; int map[MAXN][MAXN]; int color[MAXN]; int used[MAXN]; int n,m; int aa=10,ans,solved; void dfs(int pos) { // printf("%d\n",pos); if(pos==n+1) { solved=1; // if (ans>4) ans=4; aa=min(aa,ans); return; } if (!used[pos]) { ans=max(ans,1); dfs(pos+1); return; } if (ans>aa) return; // if (solved) return; for (int i=1;i<=n+1;i++) { int flag=0; for (int j=1;j<=n;j++) { if (color[j]==i&&map[pos][j]) { flag=1;break; } } if (!flag) { int t=0; if (i>ans) t=ans; ans=max(ans,i); color[pos]=i; dfs(pos+1); if (t) ans=t; // if (solved) return; color[pos]=0; } } } int main() { freopen("c.in","r",stdin); while (1) { scanf("%d\n",&n); memset(color,0,sizeof(color)); memset(map,0,sizeof(map)); memset(used,0,sizeof(used)); aa=10;ans=0; if (!n) break; for (int i=1;i<=n;i++) { char c[50]; scanf("%s\n",c); for (int j=2;j<=strlen(c+1);j++) { used[i]++; used[c[j]-'A'+1]++; map[i][c[j]-'A'+1]=1; } } dfs(1); if (aa==1) printf("%d channel needed.\n",aa); else printf("%d channels needed.\n",aa); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator