博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[算法]动态规划之最长递增子序列
阅读量:7174 次
发布时间:2019-06-29

本文共 974 字,大约阅读时间需要 3 分钟。

最长递增子序列

#include
#include
#include
#include
#define N 4int solve(int *array, int n) { int *dp = (int *)malloc(n * sizeof(int)); int i; int j; int result; bzero((void *)dp, n * sizeof(int)); dp[0] = 1; for(i = 1; i < n; i++) { *(dp + i) = *(dp + i - 1); for(j = 0; j < i; j ++) { if(*(array + i) > *(array + j)) { *(dp + i) = (*(dp + i) < *(dp + j) + 1) ? (*(dp + j) + 1) : *(dp + i); } } } result = *(dp + n -1); free(dp); return result;}int main(char ** args) { srand((unsigned)time(NULL)); int *array = (int *)malloc(N * sizeof(int)); for(int i = 0; i < N; i++) { *(array + i) = rand() % N; printf("%d\t", *(array + i)); } int ret = solve(array, N); printf("\nresult:%d\n", ret); free(array); return 0;}

 

转载于:https://www.cnblogs.com/igloo1986/p/4164690.html

你可能感兴趣的文章
JavaScript面向对象程序设计创建对象的方法分析
查看>>
程序员笔记|常见的Spring异常分析及处理
查看>>
Java基础:面向对象四大特征、五大原则
查看>>
JSP 生命周期
查看>>
量化交易系统开发:自动化(机器人或EA)交易的优点
查看>>
加拿大:监管机构呼吁加密行业参与证券法审查
查看>>
大数据技术综述
查看>>
MX4 Pro上实现一键锁屏
查看>>
ppt2010 滴管
查看>>
Learn Python The Hard Way(21)
查看>>
[读书笔记]Begining PHP5 and MySQL5 From Novoice to Professional
查看>>
OSChina 周五乱弹 ——做宇宙最低调的程序员.
查看>>
Linux下Tomcat向MySQL插入数据中文乱码解决办法
查看>>
致梦中的花
查看>>
说说new Integer和Integer.valueOf
查看>>
Zabbix server is not running:zabbix access denied
查看>>
我的友情链接
查看>>
linux下的软硬链接
查看>>
【JAVA的 IO流之FileInputStream和FileOutputStream】
查看>>
远程连接mysql 授权方法详解
查看>>