这题是最长子序列,然后再求出路径就可以了。开始写的比较乱,用数组什么的,后来用了指针就好办了。现在把代码贴出来。指针真的挺给力的。
--------------------------------------------------------------------------------------------------------------------
1 #include
2 #include
3 #include
4 using namespace std;
5 struct people
6 {
7 int num,h;
8 people* last;
9 }girl[100+5];
10 int main()
11 {
12 int n;
13 int i,j;
14 int dp[100+10];
15 stack<int>haha;
16 while(cin>>n&&n)
17 {
18 for(i&#61;1;i<&#61;n;&#43;&#43;i)
19 dp[i]&#61;1;
20 for(i&#61;1;i<&#61;n;&#43;&#43;i)
21 {
22 cin>>girl[i].h;
23 girl[i].num&#61;i;
24 girl[i].last&#61;NULL;
25 }
26 for(i&#61;1;i<&#61;n;&#43;&#43;i)
27 {
28 for(j&#61;1;jj)
29 {
30 if(girl[i].h>girl[j].h)
31 {
32 if(dp[j]&#43;1>dp[i])
33 {
34 dp[i]&#61;dp[j]&#43;1;
35 girl[i].last&#61;&girl[j];
36
37 }
38 }
39 }
40 }
41 int max&#61;0,maxsign&#61;0;
42 for(i&#61;1;i<&#61;n;&#43;&#43;i)
43 {
44 if(dp[i]>max){ max&#61;dp[i];maxsign&#61;i;}
45 }
46 cout<<"The number is ";
47 cout<<max;
48 cout<<":";
49 haha.push(girl[maxsign].num);
50 people* temple&#61;girl[maxsign].last;
51 while(temple)
52 {
53 haha.push(temple->num);
54 temple&#61;temple->last;
55 }
56 while(haha.size()>0)
57 {
58 cout<<" "<<haha.top();haha.pop();}
59 cout<<endl;
60 }
61 return 0;
62 }
63
64
65
66
67