题解 | #拦截导弹#

拦截导弹

https://www.nowcoder.com/practice/dad3aa23d74b4aaea0749042bba2358a

//dfs秒了
#include<iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include<vector>
using namespace std;

const int MAXN = 120;
const int INF = 1e6;
vector<int>height_list;
int max_count;
void dfs(int index, int max_height, int n_counts) {
    if (index == height_list.size()) {
        max_count = max(max_count, n_counts);
    } else {
        if (max_height >= height_list[index]) {
            dfs(index + 1, height_list[index], n_counts + 1);
        }
        dfs(index + 1, max_height, n_counts);
    }
}
int main() {
    max_count = 0;
    int K;
    scanf("%d", &K);
    for (int i = 0; i < K; i++) {
        int height;
        scanf("%d", &height);
        height_list.push_back(height);
    }
    dfs(0, INF, 0);
    printf("%d", max_count);


}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-01 12:22
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-03 18:22
投了几百份简历,专业和方向完全对口,都已读不回。尝试改了一下学校,果然有奇效。
steelhead:这不是很正常嘛,BOSS好的是即便是你学院本可能都会和聊几句,牛客上学院本机会很少了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务