Pagini recente » Cod sursa (job #1737678) | Cod sursa (job #2285114) | Cod sursa (job #1180244) | Istoria paginii utilizator/pricopana | Cod sursa (job #1566375)
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package programare.dinamica.sir.maximal;
/**
*
* @author Sorin
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.*;
public class ProgramareDinamicaSirMaximal {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
// TODO code application logic here
File f=new File("scmax.in");
Scanner sc;
sc = new Scanner(f);
int dim;
dim=sc.nextInt();
int []v=new int[dim];
for (int i=0;i<dim;i++)
v[i]=sc.nextInt();
int []b=new int[dim];
for (int i=0;i<dim;i++)
{
int max=0;
for (int j=0;j<i;j++)
if (v[i]>v[j] && max<b[j]) max++;
b[i]=max+1;
}
int []u=new int [dim];
int maxx=0,k;
for (int i=0;i<dim;i++) if (b[i]>maxx) maxx=b[i];
k=maxx;
for (int i=dim-1;i>=0;i--)
if (b[i]==k)
{
u[k-1]=v[i];
k--;
}
File f2=new File("D://scmax.out");
PrintWriter writer=new PrintWriter(f2);
for (int i=0;i<maxx;i++)
writer.printf("%d ",u[i]);
writer.close();
}
}