标签:
Description
Input
Output
Sample Input
Sample Output
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #define MAX_SIZE 1005 5 6 struct x 7 { 8 int weight; 9 int speed; 10 int num,sum,front; 11 }DP[MAX_SIZE]; 12 13 int comp(const void * a,const void * b); 14 int main(void) 15 { 16 int i = 0; 17 int max,max_loc,ans,ans_loc; 18 int box[MAX_SIZE]; 19 20 while(scanf("%d%d",&DP[i].weight,&DP[i].speed) != EOF) 21 { 22 DP[i].num = i; 23 DP[i].sum = 1; 24 DP[i].front = -1; 25 i ++; 26 } 27 28 qsort(DP,i,sizeof(struct x),comp); 29 30 ans_loc = 0; 31 ans = 0; 32 for(int j = 1;j < i;j ++) 33 { 34 max = 0; 35 for(int k = 0;k < j;k ++) 36 if(DP[j].weight > DP[k].weight && DP[j].speed < DP[k].speed) 37 if(DP[k].sum > max) 38 { 39 max = DP[k].sum; 40 max_loc = k; 41 } 42 43 DP[j].sum += max; 44 if(max) 45 DP[j].front = max_loc; 46 47 if(ans < DP[j].sum) 48 { 49 ans = DP[j].sum; 50 ans_loc = j; 51 } 52 } 53 54 box[0] = ans_loc; 55 i = 0; 56 while(box[i] != -1) 57 { 58 i ++; 59 box[i] = DP[box[i - 1]].front; 60 } 61 62 printf("%d\n",ans); 63 for(i --;i >= 0;i --) 64 printf("%d\n",DP[box[i]].num + 1); 65 66 return 0; 67 } 68 69 int comp(const void * a,const void * b) 70 { 71 if((*(struct x *)a).weight == (*(struct x *)b).weight) 72 return (*(struct x *)b).speed - (*(struct x *)a).speed; 73 return (*(struct x *)a).weight - (*(struct x *)b).weight; 74 }
HDU 1160 FatMouse's Speed (DP)
标签:
原文地址:http://www.cnblogs.com/xz816111/p/4180342.html