经典DP水题A
来源:互联网 发布:2016安全知识 网络竞赛 编辑:程序博客网 时间:2024/05/29 04:59
题意:给一串数字,输出从左往右由小到大的最大长度,即 1 7 3 5 9 4 8,最长为1 3 5 8 或者1 3 4 8等等,长度为4.
思路:DP,从左往右遍历一遍,更新比它小的数,统计此刻长度。
AC java 代码:
import java.util.Scanner;
//3812 KB 1563 ms
public class sdupractice0724DPA {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[][] arr = new int[n][2];
for (int i = 0; i < n; i++) {
arr[i][0] = scan.nextInt();
arr[i][1] = 1;
}
for (int i = 1; i < n; i++) {
int count = 0;
for (int j = 0; j < i; j++) {
if (arr[i][0] > arr[j][0] && arr[j][1] > count) {
count = arr[j][1];
}
}
arr[i][1] += count;
}
int max = 0;
for (int i = 0; i < n; i++) {
if (arr[i][1] > max)
max = arr[i][1];
}
System.out.println(max);
}
}
0 0
- 经典DP水题A
- HDU4340 Capturing a country 树状DP经典
- 经典DP水题B
- 经典DP水题G
- 经典DP水题C
- 经典DP水题D
- #UVA1025#A Spy in the Metro(Dp经典)
- HDU 1024 Max Sum Plus Plus 经典 DP(A)
- 经典DP
- A. Flipping Game DP水题
- A-DP
- DP经典5题 【DP】
- Codeforces 713C C. Sonya and Problem Wihtout a Legend (经典DP)
- Codeforces 713C Sonya and Problem Wihtout a Legend DP(经典)
- poj 3317 Stake Your Claim(极大极小搜索经典 a-b+剪枝+记忆化dp)
- poj 1163经典DP
- poj2385-dp经典
- ZOJ1499经典dp
- struts2页面向action提交list对象
- android飞行模式灰显不能操作问题分解
- 串口通信-异步通信方式
- 程序员的三重境界
- android中dip、px相互换算
- 经典DP水题A
- 利用反射函数实现一键清除缓存,并获取清除的缓存数目。调用反射函数类出错java.lang.NoSuchMethodException: getPackageSizeInfo.
- CSV 相关的学习
- joinColumns和inverseJoinColumns的用法
- 一致性哈希算法 应用场景
- 关于二分查找
- MyEclipse工具的使用
- HDU 2066 - 一 个人的旅行(最短路)
- 黑马程序员_Java基础——异常(第1篇)