递增数列最长(dp)

来源:互联网 发布:搞笑视频软件下载 编辑:程序博客网 时间:2024/06/02 05:01

题目:点击打开链接

#include<stdio.h>#include<cstring>#include<algorithm>using namespace std;int main(){int n,temp,max1;int a[1010],d[1010];while(~scanf("%d",&n)){max1 = 0;if(n == 0)break;memset(a , 0 , sizeof(a));for(int i = 0 ; i < n ; i++){scanf("%d",&a[i]);d[i] = a[i];}for(int i = 0 ; i < n ; i++){temp = a[i];for(int j = 0 ; j <= i ; j++){if(a[j] < temp){d[i] = max(d[i] , d[j] + temp); //在同意个i间找到最大 ,之所以用d[i]不用a[i]是因为对于i等于一个值的时候,要随时更新通一层面的最大值 }}max1 = max(max1 , d[i]); //控制最终的最大值 }printf("%d\n",max1);}return 0;}


原创粉丝点击