标签:
1 #include <stdio.h> 2 #include <iostream> 3 #include <string.h> 4 #include <algorithm> 5 #define MAXX 1000010 6 using namespace std; 7 8 struct sion 9 { 10 int w, s, k; 11 }a[1010]; 12 13 14 int cmp(sion a, sion b) 15 { 16 return a.s > b.s; 17 } 18 19 20 21 int dp[1010], re[10010], b[1010]; 22 int main() 23 { 24 int n = 0; 25 int ma = 0, mai = 0; 26 re[0] = 0; 27 while(cin >> a[n].w >> a[n].s) 28 re[n] = 0, 29 a[n].k = n + 1, 30 dp[n++] = 1; 31 32 sort(a, a + n, cmp); 33 for(int i = 0; i < n; i++) 34 { 35 for(int j = 0; j < i; j++) 36 { 37 if( a[i].w > a[j].w && dp[i] <= dp[j] + 1)//注意<= 38 { 39 dp[i] = dp[j] + 1; 40 41 re[a[i].k] = a[j].k; 42 if(ma < dp[i]) 43 ma = dp[i], mai = a[i].k; 44 } 45 46 } 47 } 48 n = 0; 49 printf("%d\n", ma); 50 while(re[mai]) 51 { 52 b[n++] = mai; 53 mai = re[mai]; 54 } 55 b[n++] = mai; 56 for(int i = n-1; i >= 0; i--) 57 printf("%d\n", b[i]); 58 }
HDU 1160 FatMouse's Speed sort+DP
标签:
原文地址:http://www.cnblogs.com/Yumesenya/p/5410842.html