hdu 2614 深搜

题意:有n道题目,a[i][j] 表示做完第 i 道题再做第 j 道题所要花费的时间。Zty每次只做比以前做过的题目更难的题目,也就是说时间比以前的长。问最多能做多少道题。(每次都从第0题开始做,第0题花费时间为0).

分析:简单深度搜索。。

 

 

const int M = 15;
int n, ans;
int a[M][M];
int b[M];

void dfs(int i,int t,int cnt){//解决完第i题 最长时间t 已解决cnt道题目
    checkmax(ans, cnt);
    FOR(j, 1, n){       //if(ans==n)return;
        if(b[j]==0 && a[i][j]>=t){
            b[j]=1;
            dfs(j, a[i][j], cnt+1);
            b[j]=0;
        }
    }
}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    #endif

    while(~scanf("%d",&n)){
        FOR(i,0,n) {
            FOR(j,0,n) scanf("%d",&a[i][j]);
            b[i]=0;
        }

        ans=0;
        dfs(0,0,1);
        printf("%d\n",ans);
    }

    return 0;
}

 

posted @ 2013-05-11 12:47  心向往之  阅读(133)  评论(0)    收藏  举报