hdu 1087 LIS 最长递增子序列的值
来源:互联网 发布:unity3d 协程重复调用 编辑:程序博客网 时间:2024/06/05 17:17
Input
Input contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.
Output
For each case, print the maximum according to rules, and one line one case.
Sample Input
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0
Sample Output
4
10
3
题解:
一道LIS的水题,注意求的是值,不是长度,模板上都是求的是长度。
代码:
#include <bits/stdc++.h>using namespace std;const int maxn = 1000+10;int a[maxn]={0};int dp[maxn];int main(){ int n; while(scanf("%d",&n)!=EOF) { if(n==0) break; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); } memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) { for(int j=0;j<i;j++) { if(a[i]>a[j]) { dp[i]=max(dp[i],dp[j]+a[i]); } } } int* pos = max_element(dp+1,dp+n+1); cout<<*pos<<endl; } return 0;}
阅读全文
0 0
- hdu 1087 LIS 最长递增子序列的值
- LIS 最长递增子序列 hdu 5773
- 最长递增子序列 LIS
- 最长递增子序列(LIS)
- 最长递增子序列(LIS)
- 最长递增子序列LIS
- 最长递增子序列LIS
- 最长递增子序列(LIS)
- 最长递增子序列LIS
- 最长递增子序列 LIS
- LIS(最长递增子序列)
- LIS-最长递增子序列
- 最长递增子序列LIS
- 最长递增子序列LIS
- 最长递增子序列LIS的O(nlogn)的求法
- 最长递增子序列问题的求解(LIS)
- 关于最长递增子序列问题的求解(LIS)
- 最长递增子序列问题的求解(LIS)
- Codeforces Round #367 (Div. 2) D题 01字典树
- a thread named [Abandoned connection cleanup thread] but has failed to stop it
- AndroidASD完全解析07之CoordinatorLayout
- Effective C++ 条款9:绝不在构造和析构过程中调用virtual函数
- ceph pg+down+peering 故障排查与osd误删恢复
- hdu 1087 LIS 最长递增子序列的值
- 机器学习决策树的算法实现
- dcloud --app版本更新
- MySQL 索引及查询优化总结
- qt调用caffe代码
- ubuntu下修改文件夹权限,更改视图权限
- LeetCode--Jump Game
- lbaselib.c解析(5.3.4)
- linxu FTP 使用方法