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 jxnuxiaoyong at 2009-08-23 21:09:27 on Problem 3740 and last updated at 2009-08-23 21:56:59
#include <iostream>
using namespace std;

int data[17][301];
int row;
int ans[301];
int m,n;

int DFS(int row)
{
    int f=0;
    int fans[301];
    int sans[301];
    if(row>m)
        return 0;
    for(int i=1;i<=n;i++)
    {
        sans[i]=ans[i];
        ans[i]=ans[i]+data[row][i];

        if(ans[i]==0)
            f=1;            
        if(ans[i]>1)
            return 0;  
    }
    if(!f)
        return 1;
    for(int i=row+1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
            fans[j]=ans[j];
        if(DFS(i))
            return 1;
        else
        {
            for(int j=1;j<=n;j++)
                ans[j]=fans[j];
        }
    }
    for(int i=1;i<=n;i++)
        ans[i]=sans[i];
    return DFS(row+1);
}
    
    
    
    
int main()
{

    while( cin>>m>>n )
    {
        for(int i=1;i<=m;i++)
            for(int j=1;j<=n;j++)
                cin>>data[i][j];
        memset(ans,0,sizeof(ans));
        if(DFS(1))
            cout<<"Yes, I found it"<<endl;
        else
            cout<<"It is impossible"<<endl;
    }
}

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