Pagini recente » Cod sursa (job #2777103) | Cod sursa (job #281485) | Cod sursa (job #1624136) | Cod sursa (job #1359759) | Cod sursa (job #2420134)
import java.io.*;
import java.util.Scanner;
import java.io.IOException;
import java.util.StringTokenizer;
public class Main {
static class Task {
class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner(String inputFile) {
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(inputFile))));
} catch (Exception e) {
}
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public final static String INPUT_FILE = "scmax.in";
public final static String OUTPUT_FILE = "scmax.out";
int n;
int[] numere;
private void readInput() {
try {
MyScanner sc = new MyScanner(INPUT_FILE);
n = sc.nextInt();
numere = new int[n + 1];
numere[0] = 0;
for (int i = 1; i <= n; i++) {
numere[i] = sc.nextInt();
}
//sc.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private void writeOutput(int result) {
try {
PrintWriter pw = new PrintWriter(new File(OUTPUT_FILE));
pw.printf("%d\n", result);
pw.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private int findMax(int current, int indice, int[] dp) {
int max = 1;
for (int i = 1; i <= indice; i++) {
if (numere[i] < current) {
if (dp[i] + 1 > max) {
max = dp[i] + 1;
}
}
}
return max;
}
private int getResult() {
// TODO: Aflati punctajul maxim pe care il puteti obtine
// planificand optim temele.
int[] dp = new int[n + 1];
dp[1] = 1;
int maxGlobal = -1;
for (int i = 2; i <= n; i++) {
int current = numere[i];
int max = findMax(current, i - 1, dp);
dp[i] = max;
if (max > maxGlobal) {
maxGlobal = max;
}
}
return maxGlobal;
}
public void solve() {
readInput();
writeOutput(getResult());
}
}
public static void main(String[] args) {
new Task().solve();
}
}