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

暴力完全可以,而且G++更快些,代码如下

Posted by zhongwen at 2011-10-10 20:27:40 on Problem 3740
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int m , n , a[16][300] , t[300] , tmp[300] ;
bool tell ;

void search( int p )
{
    int i ;
    if ( tell ) return ;
    if ( p == m )
    {
        for ( i = 0 ; i < n ; i++ )
            if ( !t[i] ) break ;
        if ( i == n ) tell = true ;
        return ;
    }
    search(p+1) ;
    for ( i = 0 ; i < n ; i++ )
    if ( t[i] && a[p][i] ) return ;
    else tmp[i] = (t[i]|a[p][i]) ;
    memcpy(t,tmp,sizeof(tmp)) ;
    search(p+1) ;
    for ( i = 0 ; i < n ; i++ )
    if ( a[p][i] ) t[i]-- ;
}

int main()
{
    int i , j , k ;
    while ( cin >> m >> n )
    {
        for ( i = 0 ; i < m ; i++ )
        for ( j = 0 ; j < n ; j++ )
            scanf( "%d" , &a[i][j] ) ;
        tell = false ;
        memset(t,0,sizeof(t)) ;
        search(0) ;
        if (tell) printf( "Yes, I found it\n" ) ;
        else printf( "It is impossible\n" ) ;
    }
}


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