Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

【我也不知道怎么做的,就ac了】可能是数据弱了,有没有数据会让我的代码wa掉啊

Posted by WilliamACM at 2013-02-15 23:12:52 on Problem 1129
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <queue>
#include <map>
using namespace std;
int n;
bool a[26][26],c[26][26];
int dfs(int v)
{
    if(v==0) return 0;
    int ans=0;
    for(int i=0;i<n;i++)
    if(v&(1<<i))
    {
        int next=0;
        for(int j=0;j<n;j++)
        if(c[i][j]&&(v&(1<<j))) next|=1<<j;

        ans=max(ans,dfs(next)+1);
    }
    return ans;

}
void init()
{
    char s[100];
    memset(c,0,sizeof(c));
    for(int i=0;i<n;i++)
    {
        scanf("%s",s);
        for(int j=2;s[j];j++)
        if(s[j]<='Z'&&s[j]>='A') c[i][s[j]-'A']=1;
    }
    int ans=dfs((1<<n)-1);
    printf("%d channel%s needed.\n",ans,ans==1?"":"s");
}
int main()
{
    //freopen("in.txt","r",stdin);
    while(scanf("%d",&n),n)
    {
        init();
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator