最长上升子序列。百炼2757 2种方法
来源:互联网 发布:stc单片机引脚功能图 编辑:程序博客网 时间:2024/06/05 09:21
很简单的动态规划
////////////////////////////////////////////////////////////////////////////////
第一种所谓的人人为我,第二种我为人人
///////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include<algorithm>using namespace std;
const int MAXN = 1000;
int a[MAXN];
int result[MAXN];
int main(){
int n;
cin>>n;
for(int i = 1;i <= n;i++)
{ cin >> a[i];
result[i] = 1;
}
for(int i = 2;i <= n;i++)
{
for(int j = 1;j <= i - 1;j++)
if(a[i] > a[j])
result[i] = max(result[j]+1,result[i]);
}
cout << *max_element(result+1,result+1+n) << endl;
}
/////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 1000;
int a[MAXN];
int result[MAXN];
int main(){
int n;
cin>>n;
for(int i = 1;i <= n;i++)
{ cin >> a[i];
result[i] = 1;
}
for(int i = 1;i <= n;i++)
{
for(int j =i + 1;j <= n ;j++)
if(a[j] > a[i])
result[j] = max(result[i]+1,result[j]);
}
cout << *max_element(result+1,result+1+n) << endl;
}
0 0
- 最长上升子序列。百炼2757 2种方法
- POJ百炼-2757-最长上升子序列
- 百练2757最长上升子序列
- 百练2757:最长上升子序列
- 百练2757:最长上升子序列
- 2757:最长上升子序列
- hdu1025!求最长上升子序列的另种方法!!!!
- 最长上升子序列的两种方法
- LIS最长上升子序列三种方法
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 编辑框中添加一个控件及程序编辑
- 网桥系列 1
- c# MVC 跳转页面
- Unity 3D——四元数的应用
- Android 实现书籍翻页效果----源码篇
- 最长上升子序列。百炼2757 2种方法
- B+/-Tree原理及mysql的索引分析
- Hibernate(五)Hibernate一对多关系映射
- linux基础--tar命令说明
- 张小龙 与 微信
- HDU2569
- POJ2586
- ATTACKING WEBSERVERS VIA .HTACCESS
- Hibernate(六)Hibernate继承关系映射