2018年全国多校算法寒假训练营练习比赛(第二场) D YB要打炉石 【最长非递减子序列】

题目描述

Wozuinb非常喜欢打炉石传说,但是菜的不行,所以他决定打
竞技场来练练手。系统按顺序给出n张卡牌,每张卡牌都有自
己的使用消耗a[i],每次只给出一张,wozuinb可以选择或者
弃掉这张牌。每选择一张牌都会按选择顺序放在卡槽中,当
卡槽中放满30张即可组成一套套牌。Wozuinb希望自己的套牌的
消耗满足一个平滑的曲线,即30张卡牌都满足第i张卡牌的消耗
不小于第i-1张(i>1)。请你帮助wozuinb看一看,这些卡牌能不
能组成想要的套牌,如果能组成输出“yes”,如果不能输出“no”。

输入描述:

第一行输入一个整数n,0

输出描述:

输出一行,“yes”或“no”

输入

5
1 2 3 4 5

输出

no

题意:就是求得最长非递减子序列

分析: 板子题略,由于范围,直接用O(N^2)了

参考代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

#define LL long long
const int maxn = 200;
int n;
int num[maxn];
int dp[maxn];

int main() {
       cin>>n;
        int ans = 0;
        for(int i = 1; i <= n; ++i) {
            scanf("%d", &num[i]);
            dp[i] = 1;
            for(int j = 1; j < i; ++j) {
                if(num[j] <= num[i]) {
                    dp[i] = max(dp[i], dp[j] + 1);
                }
            }
            ans = max(ans, dp[i]);
        }
        if(ans >= 30) {
            printf("yes\n");
        } else {
            printf("no\n");
        }
    return 0;
}
  • 如有错误或遗漏,请私聊下UP,thx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值