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

我这个怎么就wa大牛帮忙看看。。谢谢

Posted by conan1 at 2008-09-12 10:12:19 on Problem 2441
#include<stdio.h>
#include<string.h>
int n,m,map[25][25];
short dp[21][1024*1024];
int main()
{
    int i,j,k,num,x,base,cur,next,ans;
    scanf("%d%d",&n,&m);
        memset(map,0,sizeof(map));
        for(i=1;i<=n;i++)
        {
            scanf("%d",&num);
            while(num--)
            {
                scanf("%d",&x);
                map[i][x]=1;
            }
        }
        memset(dp,0,sizeof(dp));
        base=1<<m;
        dp[0][0]=1;
        for(i=1;i<=n;i++)
        {
            cur=i-1;
            for(j=0;j<base;j++)
            if(dp[cur][j]!=0)
            {
                for(k=1;k<=m;k++)
                if(map[i][k])
                {
                    next=j|(1<<(k-1));
                    //printf("%d----next\n",j|(1<<(k-1)));
                    if(next!=j)
                    {
                        dp[i][next]+=dp[cur][j];
                    }
                }
            }
        }
        ans=0;
       /* for(i=0;i<=n;i++)
        {
            for(j=0;j<base;j++)
            printf("%d ",dp[i][j]);
            putchar('\n');
        }*/
        for(i=0;i<base;i++)
        if(dp[n][i])
        ans+=dp[n][i];
        printf("%d\n",ans) ;
    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