HDU-2614 Beat
题意:给定一个n*n的矩阵,代表解决问题i到j的难度,前提是要解决越来越难的题,问最多能解决多少题。
思路:dfs找出最大值。
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2614
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 #include <string> 6 #include <algorithm> 7 #include <iostream> 8 using namespace std; 9 const int N=16; 10 11 int len[N][N]; 12 bool vis[N]; 13 int n,MAX; 14 15 void dfs(int s,int cnt,int m){ 16 MAX=max(MAX,cnt); 17 for(int i=1;i<n;i++){ 18 if(!vis[i]&&len[s][i]>=m){ 19 vis[i]=true; 20 dfs(i,cnt+1,len[s][i]); 21 vis[i]=false; 22 } 23 } 24 } 25 26 int main(){ 27 28 // freopen("data.in","r",stdin); 29 // freopen("data.out","w",stdout); 30 31 while(scanf("%d",&n)!=EOF){ 32 for(int i=0;i<n;i++) 33 for(int j=0;j<n;j++) 34 scanf("%d",&len[i][j]); 35 memset(vis,false,sizeof(vis)); 36 MAX=1; 37 vis[0]=true; 38 dfs(0,1,0); 39 printf("%d\n",MAX); 40 } 41 return 0; 42 }