-
Notifications
You must be signed in to change notification settings - Fork 2
/
HDU-dx16-1007.cpp
88 lines (82 loc) · 1.39 KB
/
HDU-dx16-1007.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
ID: mfs6174
PROG: ti
LANG: C++
*/
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
//ifstream inf("ti.in");
//ofstream ouf("ti.out");
const int maxlongint=2147483647;
int i,j,k,t,n,m,c,cc,ccc;
int shu[1100],qi[1100],zhong[1100],f[1100],tt[1100][1100];
bool tu[1100][1100],ff[1100];
void dfs(int x)
{
ff[x]=true;
if (f[x]==1)
return;
int i;
for (i=1;i<=tt[x][0];i++)
{
tu[tt[x][i]][x]=true;
dfs(tt[x][i]);
}
}
int main()
{
freopen("ti.in","r",stdin);
while(scanf("%d",&n)!=EOF)
{
for (i=1;i<=n;i++)
scanf("%d",&shu[i]);
c=cc=0;
f[1]=1;
for (i=2;i<=n;i++)
{
f[i]=1;
for (j=1;j<i;j++)
if (shu[j]<shu[i])
{
if (f[j]+1>f[i])
{
f[i]=f[j]+1;
ccc=1;tt[i][ccc]=j;
}
else
if (f[j]+1==f[i])
{
ccc++;tt[i][ccc]=j;
}
}
tt[i][0]=ccc;
}
int mm=0;
for (i=1;i<=n;i++)
mm=max(mm,f[i]);
memset(ff,0,sizeof(ff));
memset(tu,0,sizeof(tu));
for (i=1;i<=n;i++)
if (f[i]==mm)
{
cc++;
zhong[cc]=i;
dfs(i);
}
for (i=1;i<=n;i++)
if (f[i]==1&&ff[i])
{
c++;
qi[c]=i;
}
cout<<mm<<endl;
}
return 0;
}