Hang Gliding

原题链接
错误思路:
  枚举每一个人,优先队列贪心求最小的不重合区间组数.
思路:
  实际上贪心不一定能贪到正解,这里类似背包需要枚举所有可能.背包体积是时间:

\[f[i] = f[i-1],f[node[pos].l]+w \]

需要按区间右端点排序.

Code

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair<int,double> PID;
typedef pair<double,int> PDI;
const int N = 10010,M = 110;
const double eps = 1e-6;
int n,m,maxn;
double sc[M][N],f[N];
PDI res[M];
struct Node{
	int l,r,id,val;
	bool operator<(const Node& x){
		return this->r<x.r;
	}
}node[N];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&node[i].l,&node[i].r,&node[i].val);
		node[i].id = i;
		maxn = max(node[i].r,maxn);
	}
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++) scanf("%lf",&sc[i][j]);
	sort(node+1,node+n+1); 
	for(int i=1;i<=m;i++)
	{
		int pos = 1;
		for(int j=0;j<=maxn;j++)
		{
			f[j] = f[j-1];
			while(node[pos].r==j)
			{
				f[j] = max(f[j],f[node[pos].l]+node[pos].val*sc[i][node[pos].id]);
				pos++;
			}
		}
		res[i] = {f[maxn],i};
	}
	sort(res+1,res+m+1);
	for(int i=m;i>=m-2;i--)
		printf("%d %.2lf\n",res[i].second,res[i].first);
	return 0;
}
posted @ 2021-07-20 19:31  acmloser  阅读(98)  评论(0编辑  收藏  举报