题目描述
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