poj1828

找动态规划的题,却找到这道,动态规划该怎么做不知道,只会结构体二级排序。。。

#include <iostream>
#include <algorithm>
using namespace std;

#define N 50002

struct Position
{
	int x, y;
} monkey[N];

bool compare(const Position &a, const Position &b)
{
	if(a.x != b.x)
		return a.x > b.x;
	else 
		return a.y > b.y;
}

int main()
{
	int n, i, cnt, tmp;
	
	while(scanf("%d", &n) && n)
	{
		for(i = 0; i < n; i++)
			scanf("%d%d", &monkey[i].x, &monkey[i].y);
		sort(monkey, monkey+n, compare);
		cnt = 1;
		tmp = monkey[0].y;
		for(i = 1; i < n; i++){
			if(monkey[i].y > tmp){
				cnt++;
				tmp = monkey[i].y;
			}
		}
		printf("%d\n", cnt);
	}
	return 0;
}


 

你可能感兴趣的:(struct)