hdu1160FatMouse's Speed

比我的代码更好的提示

typedef struct
{

    int
 w,s;
    int
 len,index;
    int
 before;
}
mice;

建立数据结构时,用index来记录真实的位置,用before来记录排序后,这个元素上一个元素的位置

max = m[j].len;
flag = j;

用j来表示最大的那个数

贴上我ACCEPT的代码吧

#include "iostream"
#include "algorithm"
using namespace std;
struct student{
  int weight,speed;
}num[1000],s[10000];
struct{
  int a,pre;
}dp[10000];
bool cmp(student a,student b){return a.weight<b.weight;}
int max(int a,int b){return a>b?a:b;}

int main(){
  int top=1,i,j,maxb=1,list[10000],y,t;
  while(cin>>num[top].weight>>num[top].speed){s[top].weight=num[top].weight;s[top].speed=num[top].speed;dp[top].a=1;dp[top++].pre=0;};
  sort(num+1,num+top,cmp);
  //for(i=1;i<top;i++)cout<<num[i].weight<<' '<<num[i].speed<<endl;
  for(i=2;i<top;i++){
     for(j=1;j<i;j++){
      if(num[j].speed>num[i].speed&&num[j].weight<num[i].weight){
        if(dp[i].a<dp[j].a+1){dp[i].a=dp[j].a+1;dp[i].pre=j;}
        if(maxb<dp[i].a){maxb=dp[i].a;y=i;}
        //cout<<"i "<<i<<" j "<<j<<endl;
      }
     }
  }
  t=top;
  top=1;
  while(y){
    list[top++]=y;
    y=dp[y].pre;
  }
  cout<<maxb<<endl;
  for(i=top-1;i>=1;i--){
    for(j=1;j<t;j++)
      if(num[list[i]].weight==s[j].weight&&num[list[i]].speed==s[j].speed)
       cout<<j<<endl;
  }
}

 

posted @ 2013-08-25 19:48  龙城星  阅读(202)  评论(0编辑  收藏  举报