【DP坑多】HNU2021校赛Doorman门童

Description
Playf came to a mysterious place as a volunteer. His task was to receive contestants at the door of
the hotel. This profession is called doorman. It is known that the distance from the resting sofa to the door is L meters, and the walking speed of
playf is 1 m/s. Playf can only receive contestants when standing at the door (means that the distance
between playf and the door is 0), and playf can receive contestants instantly. At time 0, playf is standing at the door and his happiness is 0. When playf walks from the sofa to the
door, the happiness of playf decreases by x every second, while standing at the door, happiness
decreases by y every second, while walking toward the sofa, it decreases z every second, and when
sitting on the sofa, happiness increases by w every second. Playf can sit on the sofa only when the
distance between the playf and the sofa is 0. It is known that a total of n contestants will come to the hotel, the arrival time of the i-th contestant
is ai, and his patience is bi. For the i-th contestant, if playf does not stand at the door to receive him
during the time period [ai, ai+bi], playf will be fired due to his poor work. What’s more, each contestant
has a friendly value ci, when playf receives contestant i at time t , his happiness will increase ci *
(ai+bi-t). After receiving all the contestants, the task of playf is completed. Now playf wants to ask you, without getting fired, what is the maximum happiness he can get at the
moment the task is completed. 1≤L, ai, bi ≤10^9, 1≤ n ≤ 1000, 1≤ x,y,z,w, ci ≤200
It’s grantee that z ≤ y ≤ x and 2y ≤ x+z
Input
The first line contain six integers n, L, x, y, z, w, their meaning is as mentioned above. The following n lines, each line contain three integers ai, bi, ci, indicate i-th contestant’s arrival time, patience and friendly value. Output
Output one integer indicate the answer.Sample Input Output for Sample input
2 3 3 2 1 3
5 5 5
15 8 1
39
In [0,5], playf has been standing at the door, happiness decreases by 10
At time 5, playf received the first contestant, and happiness increased by 5
(5+5-5)=25
In [5,8], playf walks from the door to the sofa, happiness decreases by 13=3
In [8,20], playf has been sitting on the sofa, happiness increases by 12
3=36
In [20,23], playf walks from the sofa to the door, happiness decreases by 33=9
At time 23, playf received the second contestant. The happiness is increased by 1
(18+5-23)=0
The final happiness is -10+25-3+36-9=39

#include<bits/stdc++.h>
#ifdef LOCAL
FILE*FP=freopen("text.in","r",stdin);
#endif
using namespace std;
#define INF 0x3f3f3f3f 
#define N 2010
#define int long long
struct In{
	int a,b,c;
}in[N];
struct So{
	int t,f,g,id,r,c;//f:0起点1终点
	bool operator <(So x){
		return t<x.t;
	}
}so[N],cp[N];

struct Dp{
	int d,t,f,g,v,c;//t用于计算 v0可1不可 
}dp[N];//0为开始点 
int n,l,x,y,z,w;
signed main(){
	scanf("%d%d%d%d%d%d",&n,&l,&x,&y,&z,&w);
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&in[i].a,&in[i].b,&in[i].c);
		so[2*i].t=in[i].a,so[2*i].f=0,so[2*i].g=2*i+1,so[2*i].id=2*i,so[2*i].c=in[i].c;
		so[2*i+1].t=in[i].a+in[i].b,so[2*i+1].f=1,so[2*i+1].g=2*i,so[2*i+1].id=2*i+1,so[2*i+1].c=in[i].c; 
	}
	memcpy(cp,so,sizeof(so));
	sort(cp,cp+2*n);
	for(int j=0;j<2*n;j++){
		so[cp[j].id].r=j+1;
	}
	dp[0].d=0,dp[0].t=0,dp[0].v=0; 
	for(int i=0;i<2*n;i++){
		dp[so[i].r].d=-INF;
		dp[so[i].r].f=so[i].f;
		dp[so[i].r].g=so[so[i].g].r;
		dp[so[i].r].t=so[i].t;
		dp[so[i].r].v=0;
		dp[so[i].r].c=so[i].c;
	}
	/*
	for(int i=0;i<=2*n;i++){
		printf("dp[%d]:d=%d,t=%d,f=%d,g=%d,v=%d,c=%d\n",i,dp[i].d,dp[i].t,dp[i].f,dp[i].g,dp[i].v,dp[i].c);
	}
	putchar('\n');
	*/
	int ml;
	for(int i=2*n;i>=0;i--){
		if(dp[i].f==0&&dp[i].t!=dp[i-1].t){//bug:注意重叠的情况,这样处理保证拿到全部后不会在走到沙发 
			ml=i;
			break;
		}
	}	
	for(int i=1;i<=2*n;i++){
		dp[i].d=dp[i-1].d-(dp[i].t-dp[i-1].t)*y;
		if(dp[i].f==0){
			dp[i].d+=dp[i].c*(dp[dp[i].g].t-dp[i].t);
		}
		//printf("door:dp[%d]:d=%d\n\n",i,dp[i].d);
		//bug:sum可能开始就有 
		int sum=(dp[i].f==0?(dp[dp[i].g].t-dp[i].t)*dp[i].c:0),temp;//愉快 
		//printf("sum:%d\n",sum);
		for(int j=i-1;j>=0;j--){
			int dt=dp[i].t-dp[j].t;
			int te=w*(dt-2*l)-(x+z)*l;
			if(dp[j].f==0&&dp[dp[j].g].t<dp[i].t&&j!=0){
				dp[j-1].v=1;
				//printf("tag:%d\n",j-1);
				//bug:去掉原来的break 
			}
			temp=sum;
			if(dp[j].f==0&&dp[dp[j].g].t>dp[i].t){//bug:要比时间因为有最后一次 
				sum+=(dp[dp[j].g].t-dp[i].t)*dp[j].c;
				//printf("dp[dp[j].g].t:%d dp[i].t:%d dp[j].c:%d\n",dp[dp[j].g].t,dp[i].t,dp[j].c);
				//printf("j:%d gtv:%d sum:%d\n",j,(dp[dp[j].g].t-dp[i].t)*dp[j].c,sum);
			}
			if(dp[j].v==1)break; 
			if(dt<=2*l)continue;
			if(j>=ml)continue;
			//printf("j=%d dt=%d te=%d sum=%d dp[%d].d+%d=%d\n",j,dt,te,sum,j,sum,dp[j].d+sum);
			dp[i].d=max(dp[i].d,dp[j].d+temp+te);//还是暂时不能用sum,因为可能重复算 
			//printf("now:dp[%d]:d=%d\n",i,dp[i].d);
		}
		//printf("dp[%lld]:d=%lld\n\n",i,dp[i].d);
	}
	int ma=-INF;
	for(int i=ml;i<=2*n;i++){
		//printf("to:%d dp:%d\n",i,dp[i].d);
		//bug:可能从门来也可以,要的是到了最后一个就不要再躺沙发了 
		//if(dp[ml].g==i)continue;
		ma=max(ma,dp[i].d);
	}//bug:做完就走 
	printf("%lld\n",ma);//bug:居然还要开 long long 
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C语言是一种广泛使用的编程语言,它具有高效、灵活、可移植性强等特点,被广泛应用于操作系统、嵌入式系统、数据库、编译器等领域的开发。C语言的基本语法包括变量、数据类型、运算符、控制结构(如if语句、循环语句等)、函数、指针等。在编写C程序时,需要注意变量的声明和定义、指针的使用、内存的分配与释放等问题。C语言中常用的数据结构包括: 1. 数组:一种存储同类型数据的结构,可以进行索引访问和修改。 2. 链表:一种存储不同类型数据的结构,每个节点包含数据和指向下一个节点的指针。 3. 栈:一种后进先出(LIFO)的数据结构,可以通过压入(push)和弹出(pop)操作进行数据的存储和取出。 4. 队列:一种先进先出(FIFO)的数据结构,可以通过入队(enqueue)和出队(dequeue)操作进行数据的存储和取出。 5. 树:一种存储具有父子关系的数据结构,可以通过中序遍历、前序遍历和后序遍历等方式进行数据的访问和修改。 6. 图:一种存储具有节点和边关系的数据结构,可以通过广度优先搜索、深度优先搜索等方式进行数据的访问和修改。 这些数据结构在C语言中都有相应的实现方式,可以应用于各种不同的场景。C语言中的各种数据结构都有其优缺点,下面列举一些常见的数据结构的优缺点: 数组: 优点:访问和修改元素的速度非常快,适用于需要频繁读取和修改数据的场合。 缺点:数组的长度是固定的,不适合存储大小不固定的动态数据,另外数组在内存中是连续分配的,当数组较大时可能会导致内存碎片化。 链表: 优点:可以方便地插入和删除元素,适用于需要频繁插入和删除数据的场合。 缺点:访问和修改元素的速度相对较慢,因为需要遍历链表找到指定的节点。 栈: 优点:后进先出(LIFO)的特性使得栈在处理递归和括号匹配等问题时非常方便。 缺点:栈的空间有限,当数据量较大时可能会导致栈溢出。 队列: 优点:先进先出(FIFO)的特性使得
C语言是一种广泛使用的编程语言,它具有高效、灵活、可移植性强等特点,被广泛应用于操作系统、嵌入式系统、数据库、编译器等领域的开发。C语言的基本语法包括变量、数据类型、运算符、控制结构(如if语句、循环语句等)、函数、指针等。下面详细介绍C语言的基本概念和语法。 1. 变量和数据类型 在C语言中,变量用于存储数据,数据类型用于定义变量的类型和范围。C语言支持多种数据类型,包括基本数据类型(如int、float、char等)和复合数据类型(如结构体、联合等)。 2. 运算符 C语言中常用的运算符包括算术运算符(如+、、、/等)、关系运算符(如==、!=、、=、<、<=等)、逻辑运算符(如&&、||、!等)。此外,还有位运算符(如&、|、^等)和指针运算符(如、等)。 3. 控制结构 C语言中常用的控制结构包括if语句、循环语句(如for、while等)和switch语句。通过这些控制结构,可以实现程序的分支、循环和多路选择等功能。 4. 函数 函数是C语言中用于封装代码的单元,可以实现代码的复用和模块化。C语言中定义函数使用关键字“void”或返回值类型(如int、float等),并通过“{”和“}”括起来的代码块来实现函数的功能。 5. 指针 指针是C语言中用于存储变量地址的变量。通过指针,可以实现对内存的间接访问和修改。C语言中定义指针使用星号()符号,指向数组、字符串和结构体等数据结构时,还需要注意数组名和字符串常量的特殊性质。 6. 数组和字符串 数组是C语言中用于存储同类型数据的结构,可以通过索引访问和修改数组中的元素。字符串是C语言中用于存储文本数据的特殊类型,通常以字符串常量的形式出现,用双引号("...")括起来,末尾自动添加'\0'字符。 7. 结构体和联合 结构体和联合是C语言中用于存储不同类型数据的复合数据类型。结构体由多个成员组成,每个成员可以是不同的数据类型;联合由多个变量组成,它们共用同一块内存空间。通过结构体和联合,可以实现数据的封装和抽象。 8. 文件操作 C语言中通过文件操作函数(如fopen、fclose、fread、fwrite等)实现对文件的读写操作。文件操作函数通常返回文件指针,用于表示打开的文件。通过文件指针,可以进行文件的定位、读写等操作。 总之,C语言是一种功能强大、灵活高效的编程语言,广泛应用于各种领域。掌握C语言的基本语法和数据结构,可以为编程学习和实践打下坚实的基础。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值