标签:dfs
很水的。但是wa了很多遍,因为写num【1】【1】。。。
改成0之后就过了。。。虽然不知道为什么。。。
3 0 0 0 1 0 1 1 0 0 3 0 2 2 1 0 1 1 1 0 5 0 1 2 3 1 0 0 2 3 1 0 0 0 3 1 0 0 0 0 2 0 0 0 0 0
3 2 4HintHint: sample one, as we know zty always solve problem 0 by costing 0 minute. So after solving problem 0, he can choose problem 1 and problem 2, because T01 >=0 and T02>=0. But if zty chooses to solve problem 1, he can not solve problem 2, because T12 < T01. So zty can choose solve the problem 2 second, than solve the problem 1.
#include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <limits.h> #include <ctype.h> #include <string.h> #include <string> #include <math.h> #include <algorithm> #include <iostream> #include <queue> #include <stack> #include <deque> #include <vector> #include <set> #include <map> using namespace std; #define MAXN 20 int num[MAXN][MAXN]; int vis[200]; int n; int ans; int Max(int a,int b){ return a>b?a:b; } void DFS(int h,int count,int t){ int i; ans = Max(ans,t); for(i=1;i<=n;i++){ /*if(vis[i] == 1){ continue; } if(num[h][i] < count){ continue; }*/ if(vis[i]==0 && num[h][i]>=count){ vis[i] = 1; DFS(i,num[h][i],t+1); vis[i] = 0; } /*vis[i] = 1; DFS(i,num[h][i],t+1); vis[i] = 0;*/ } } int main(){ int i,j; while(~scanf("%d",&n)){ memset(vis,0,sizeof(vis)); /*for(i=0;i<MAXN;i++){ for(j=0;j<MAXN;j++){ num[i][j] = 0; } }*/ for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ scanf("%d",&num[i][j]); } } vis[1] = 1; ans = 0; //printf("%d\n",num[1][1]); DFS(1,0,1); printf("%d\n",ans); } return 0; }
标签:dfs
原文地址:http://blog.csdn.net/zcr_7/article/details/40897625