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 |
暴力完全可以,而且G++更快些,代码如下#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator