题解 | #拦截导弹#

拦截导弹

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);


}

全部评论

相关推荐

勉勉强强过了两题,没发挥好
投递字节跳动等公司10个岗位
点赞 评论 收藏
分享
海尔太过分了,92学历都被卡死了,你到底要什么样的人才????
皮格吉:一样,不过也干脆,没测评没笔试,直接挂不折腾人。
投递海尔等公司10个岗位
点赞 评论 收藏
分享
09-01 10:50
已编辑
东华大学 C++
PDD校招_内推:拼多多意向和开奖一般都比较晚,可能10月11月才出意向
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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