HDOJ1160 FatMouse's Speed 弄了一晚上还是WA了,感觉有不止一个解啊

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
using namespace std;
struct FatMouse
{
	int id;
	int next;
	int weight;
	int speed;
	FatMouse(int w,int s)
	{
		weight = w;
		speed = s;
	}
	bool operator<(FatMouse f)
	{
		if (weight == f.weight)
		{
			return speed > f.speed;
		}
		return weight < f.weight;
	}
};
int main()
{
	ifstream cin("input.txt");
	int w,s,max=0,index=0,n=1;
	int dp[1000];
	vector<FatMouse> v;
	while(cin>>w>>s)
	{
		FatMouse f(w,s);
		f.id=n++;
		v.push_back(f);
	}
	n--;
	sort(v.begin(),v.end());
	for (vector<FatMouse>::iterator it = v.begin() ; it != v.end(); it++)
	{
		cout<<(*it).weight<<" "<<(*it).speed<<" "<<(*it).id<<endl;
	}
	for (int i = v.size()-1;i>=0;i--)
	{
		dp[i] = 1;
		for (int j = i+1 ; j < v.size() ; j++)
		{
			if (v[i].weight < v[j].weight && v[i].speed > v[j].speed)
			{
				if (dp[i] < dp[j] + 1)
				{
					dp[i] = dp[j] + 1;
					v[i].next = j;
				}
			}
			if(max < dp[i])
			{
				max = dp[i];
				index = i;
			}
		}
		
	}
	cout<<max<<endl;
	for (int i = 1 ; i <= max ; i++)
	{
		cout<<v[index].id<<endl;
		index=v[index].next;
	}

	
}

你可能感兴趣的:(HDOJ1160 FatMouse's Speed 弄了一晚上还是WA了,感觉有不止一个解啊)