题目:

Beat

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2449    Accepted Submission(s): 1400

Problem Description

Zty is a man that always full of enthusiasm. He wants to solve every kind of difficulty ACM problem in the world. And he has a habit that he does not like to solve
a problem that is easy than problem he had solved. Now yifenfei give him n difficulty problems, and tell him their relative time to solve it after solving the other one.
You should help zty to find a order of solving problems to solve more difficulty problem. 
You may sure zty first solve the problem 0 by costing 0 minute. Zty always choose cost more or equal time’s problem to solve.

Input

The input contains multiple test cases.
Each test case include, first one integer n ( 2< n < 15).express the number of problem.
Than n lines, each line include n integer Tij ( 0<=Tij<10), the i’s row and j’s col integer Tij express after solving the problem i, will cost Tij minute to solve the problem j.

Output

For each test case output the maximum number of problem zty can solved.

Sample Input

 

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

Sample Output

 

3 2 4

题意:

Zty做题,有n道题,给定一个n*n的矩阵,T[i][j]表示做完题i后做题j需要花费的时间,Zty做题只做比他做的上一道题花费时间多的题目,问他最多能做多少道题。

分析:

bfs广搜,题目被做出来的状态会改变,可以直接将其储存在节点中,也可以用状态压缩进行储存。

代码:

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<queue>
using namespace std;

int N;
int G[16][16];
bool vis[16];
struct node{
    int val,id,sum;
    bool v[16];//直接将题目被做出来的状态储存在节点中,用状态压缩更好
};

int bfs(){
    queue<node> q;
    node st;
    st.val = 0;
    st.id = 0;
    st.sum = 1;
    memset(st.v,false,sizeof(st.v));
    st.v[0] = true;
    q.push(st);
    int ans = 1;
    while(!q.empty()){
        node cur = q.front();
        q.pop();
        for(int i=0;i<N;i++){
            node nex;
            nex.id = i;
            nex.val = G[cur.id][i];
            nex.sum = cur.sum;
            if(cur.v[nex.id] || nex.val < cur.val) continue;
            memcpy(nex.v,cur.v,sizeof(cur.v));
            nex.v[nex.id] = true;
            nex.sum++;
            if(nex.sum>ans) ans = nex.sum;
            q.push(nex);
        }
    }
    return ans;
}

int main(){
    while(cin >> N){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                cin >> G[i][j];
            }
        }

int res = bfs();
        cout << res << endl;
        //cout << endl;
    }
    return 0;
}

HDOJ-2614 Beat bfs广搜相关推荐

  1. BFS广搜解决迷宫问题java实现

    目录 1.例题 题目描述 输入 输出 测试数据 2. 思路分析 基本思想 具体步骤 代码实现 3.BFS小结 求解思路: 注意 1.例题 题目描述 迷宫由 n 行 m 列的单元格组成,每个单元格要么是 ...

  2. 2020 年百度之星·程序设计大赛 - 初赛一 Civilization BFS广搜

    problem Civilization Accepts: 619 Submissions: 2182 Time Limit: 6000/3000 MS (Java/Others) Memory Li ...

  3. 抓住那头牛(BFS广搜)

    描述 农夫知道一头牛的位置,想要抓住它.农夫和牛都位于数轴上,农夫起始位于点N(0≤N≤100000),牛位于点K(0≤K≤100000).农夫有两种移动方式: 1.从X移动到X-1或X+1,每次移动 ...

  4. 训练赛一:bfs广搜题目 CF115B Lawnmower

    CF115B Lawnmower time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  5. DFS深搜与BFS广搜专题

    一般搜索算法的流程框架 DFS和BFS与一般搜索流程的关系 如果一般搜索算法流程4使用的是stack栈结构(先进后出,后进先出)那么就会越搜越深.即,DFS,DFS只保存当前一条路径,其目的是枚举出所 ...

  6. 蓝桥杯 青蛙跳杯子【第八届】【省赛】【C组】 BFS 广搜

    资源限制 时间限制:1.0s   内存限制:256.0MB X星球的流行宠物是青蛙,一般有两种颜色:白色和黑色. X星球的居民喜欢把它们放在一排茶杯里,这样可以观察它们跳来跳去. 如下图,有一排杯子, ...

  7. POJ 3669 Meteor Shower 流星雨 解题思路心得 BFS广搜 C/C++AC代码(另有TLE不知其因)

    原题 http://poj.org/problem?id=3669 题意 贝西(Bessie)听说即将发生一场异常的流星雨;有报道称这些流星将坠入大地并摧毁其所击中的任何东西,为安全着急,她发誓要找到 ...

  8. BFS广搜例题,问题引入 --- 阿狗荒岛逃生系列(其一)

    该例题来自我的学长,感谢学长们对我的带领: 例题简述: 代码及详细注释: #include<bits/stdc++.h> using namespace std; struct Node{ ...

  9. [USACO12OPEN]Unlocking Block【BFS / 广搜】

    Pro Luogu3053 Sol 真的只是一个BFSBFSBFS!!!一个氧气都救不了的程序(快读+快写还TLETLETLE了一个点) 大体思路:对于每一种状态,我们枚举三个模块是否可以向左向右向上 ...

最新文章

  1. NSCache和NSURLCache网络缓存优化
  2. Windows 2008 R2+iis7.5环境下Discuz!X3论坛伪静态设置方法
  3. 你能排第几?2016互联网行业薪酬数据分析
  4. JavaWeb中集成UEditor
  5. linux路由内核实现分析(四)---路由缓存机制(4)
  6. [转载] python中字典中追加_python 中字典中的删除,pop 方法与 popitem 方法
  7. 提示学习 | Prompt-Tuning这么好用?
  8. Servlet教程第6讲笔记
  9. MySQL8.0下载及安装教程
  10. 如何使用微信小程序第三方UI组件库
  11. 企业微信第三方应用Demo源码
  12. 原生js页面滚动顶部显示滚动总进度条效果
  13. 计算机远程桌面连接有几种方式,远程桌面连接的2种方法
  14. D - 一只小蜜蜂...
  15. 数据清洗整理基本操作(R:dplyr、tidyr、lubridate)
  16. centos8安装docker运行java文件
  17. Bilibili批量取消关注
  18. DOTA2匹配机制详解
  19. 三言二拍:五年有多长对牛乱弹琴 | Playinamp;#39; with IT
  20. 单枪匹马想要搞定亿级流量?2021阿里都换成这个牛逼架构了

热门文章

  1. 对于ssd对小目标检测效果的思考
  2. C/C++解析硬盘分区信息
  3. 2017计算机二级c语言试题,2017年计算机二级C语言试题
  4. 程序员,到底要不要去外包公司?
  5. 爬取豌豆荚app数据
  6. [TextMatch框架] 简介
  7. 数据结构上机应用:栈和队列
  8. 大三小生浅谈如何学C
  9. 离线状态下配置深度学习服务器-在ubuntu16.04 上安装python,pip以及包
  10. SQL exists 删除重复记录