• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Hug_Sea
博客园    首页    新随笔    联系   管理    订阅  订阅

HDU-2614 Beat

题意:给定一个n*n的矩阵,代表解决问题i到j的难度,前提是要解决越来越难的题,问最多能解决多少题。

思路:dfs找出最大值。

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2614

 

View Code
 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 }
posted @ 2012-06-19 20:30  Hug_Sea  阅读(125)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3