HDOJ 1160 FatMouse's Speed

#include <stdio.h> #include <stdlib.h> typedef struct s_mouse{ int id; int weight; int speed; }s_mouse; static s_mouse mice[1000]; static int m[1000]; static int s[1000]; //static int p[1000]; static int num; int m_compare(const void *a,const void *b) { s_mouse *a_m=(s_mouse *)a; s_mouse *b_m=(s_mouse *)b; if(a_m->weight == b_m->weight && a_m->speed == b_m->speed) return 0; if(a_m->weight < b_m->weight || a_m->weight == b_m->weight && a_m->speed > b_m->speed) return -1; return 1; } static void fat_mouse() { //1. sort qsort(mice,num,sizeof(s_mouse),m_compare); //2. Dynamic Programming //2.1 initialize m[num-1]=1; s[num-1]=0; //2.2 scan int i,j; for(i=num-2;i>=0;i--){ int max=1; int maxi=0; for(j=num-1;j>i;j--){ if(mice[i].weight<mice[j].weight && mice[i].speed>mice[j].speed){ if(max<m[j]+1){ max=m[j]+1; maxi=j; } } } m[i]=max; s[i]=maxi; } } int main(int argc,char *argv[]) { int i; for(i=0;scanf("%d%d",&mice[i].weight,&mice[i].speed)>0;i++) mice[i].id=i+1; num=i; fat_mouse(); int max_index=0; for(i=num-1;i>0;i--) if(m[i]>m[max_index]) max_index=i; printf("%d\n",m[max_index]); for(i=max_index;s[i]!=0;){ printf("%d\n",mice[i].id); i=s[i]; } printf("%d\n",mice[i].id); return 0; }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值