//题目信息
//本题主要是用动态规划。参考寂静山林的博客,写的非常详细(),这里只是做个个人随笔记录 //2012/2/28 //accepted // #include#include #include using namespace std; #define MAXNUM 1000 void backtrack(int index); class elephant { public: int index; int weight; int iq; bool operator < (const elephant &other) const { if(weight!=other.weight) return weight other.iq; } }; elephant elephants[MAXNUM]; int length[MAXNUM]; int parent[MAXNUM]; int main() { int index=0,weight,iq; int i,j; while(cin>>elephants[index].weight>>elephants[index].iq) { elephants[index].index=index; index++; } sort(elephants,elephants+index); for(i=0;i iq) if(length[i] <= length[j]) { length[i]=length[j]+1; parent[i]=j; } } if(maxLength
动态规划,回溯法输出解,以及父节点记录的方法。。