1 {{{
2 #!cplusplus
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include
18 #include
19 using namespace std;
20 const int N=1010;
21 struct Mice
22 {
23 int w;
24 int s;
25 int id;
26 };
27 int n;
28 Mice a[N];
29 int b[N];
30 int c[N];
31 int len;
32 int d[N];
33 bool Cmp(const Mice &b,const Mice &c)
34 {
35 return (b.w<c.w||b.w==c.w&&b.s>c.s);
36 }
37 void DP()
38 {
39 sort(a,a+n,Cmp);
40 b[0]=1;
41 c[0]=-1;
42 for(int i=1;i<n;i++)
43 {
44 b[i]=1;
45 c[i]=-1;
46 for(int j=0;j<i;j++)
47 {
48 if(a[j].w<a[i].w && a[j].s>a[i].s&&b[j]+1>b[i])
49 {
50 b[i]=b[j]+1;
51 c[i]=j;
52 }
53 }
54
55 }
56 int max=n-1;
57 for(int j=n-1;j>=0;j--)
58 if(b[j]>b[max]) max=j;
59
60 int j=max;
61 len=b[max];
62 while(c[j]!=-1)
63 {
64 d[--len]=a[j].id;
65 j=c[j];
66 }
67 d[0]=a[j].id;
68 cout<<b[max]<<endl;
69 for(int i=0;i<b[max];i++)
70 cout<<d[i]<<endl;
71 }
72
73 int main()
74 {
75 int id;
76 id=0;
77 int weight,speed;
78 while(cin>>weight)
79 {
80 cin>>speed;
81 a[id].w=weight;
82 a[id].s=speed;
83 a[id].id=id+1;
84 id++;
85 }
86 n=id;
87 DP();
88
89 }
hdu1160 参考答案 (2008-11-12 14:07:43由218编辑)