Gym104095L 送外卖

https://codeforces.com/gym/104095/attachments/download/18184/statements.pdf

首先这个 n14 的数据范围可以直接考虑状压了。设 fi,S,time 为当前骑手在 i 号城市,已经把外卖送给了状态为 S 的城市,此时的时间为 times 所能获得的最大收益。当 time201 时表示此时的时间为 >200 的答案。

考虑一个小事实:由于起始时间是整数 0,且到达某个城市的最短时间为整数,因此如果我们到达某城市的时间为小数,那么我们一定通过调整速度(路程除以时间)使得到达时间变为整数,从而能将时间压入状态内。

转移考虑枚举先前在城市 j 送外卖,和在城市 j 时的时间 time,那么在 j 号城市时送过外卖的状态即为 S=S|2i1,将 time200time=201 分开转移:

  • fi,S,time=maxtime=0timedisi,jfj,S,time+pi,,其中 pi, 表示送达时间为 time 时的价值,disi,j 表示 i,j 间最短路。
  • fi,S,201=maxtime=0201fj,S,time+pi,di+1

时间复杂度 O(2nn2t2),不能通过。

但是发现转移相当于取某段前缀的 max,前缀和优化掉一个 t,时间复杂度 O(2nn2t),也许可以通过。过不掉的请卡常。

点击查看代码
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<unordered_map>
#include<vector>
#include<queue>
#include<bitset>
#include<set>
#include<ctime>
#include<random>
#define x1 xx1
#define y1 yy1
#define IOS ios::sync_with_stdio(false)
#define ITIE cin.tie(0);
#define OTIE cout.tie(0);
#define FlushIn fread(Fread::ibuf,1,1<<21,stdin)
#define FlushOut fwrite(Fwrite::obuf,1,Fwrite::S-Fwrite::obuf,stdout)
#define PY puts("Yes")
#define PN puts("No")
#define PW puts("-1")
#define P__ puts("")
#define PU puts("--------------------")
#define popc __builtin_popcount
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define gc getchar
#define pc putchar
#define pb emplace_back
#define rep(a,b,c) for(int a=(b);a<=(c);a++)
#define per(a,b,c) for(int a=(b);a>=(c);a--)
#define reprange(a,b,c,d) for(int a=(b);a<=(c);a+=d)
#define perrange(a,b,c,d) for(int a=(b);a>=(c);a-=d)
#define graph(i,j,k,l) for(int i=k[j];i;i=l[i].nxt)
#define lowbit(x) (x&-x)
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
#define mem(x,y) memset(x,y,sizeof x)
//#define double long double
#define int long long
//#define int __int128
using namespace std;
bool greating(int x,int y){return x>y;}
bool greatingll(long long x,long long y){return x>y;}
bool smallingll(long long x,long long y){return x<y;}
namespace Fread {
	const int SIZE=1<<21;
	char ibuf[SIZE],*S,*T;
	inline char getc(){if(S==T){T=(S=ibuf)+fread(ibuf,1,SIZE,stdin);if(S==T)return '\n';}return *S++;}
}
namespace Fwrite{
	const int SIZE=1<<21;
	char obuf[SIZE],*S=obuf,*T=obuf+SIZE;
	inline void flush(){fwrite(obuf,1,S-obuf,stdout);S=obuf;}
	inline void putc(char c){*S++=c;if(S==T)flush();}
	struct NTR{~NTR(){flush();}}ztr;
}
/*#ifdef ONLINE_JUDGE
#define getchar Fread::getc
#define putchar Fwrite::putc
#endif*/
inline int rd(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}return x*f;
}
inline void write(int x,char ch='\0'){
	if(x<0){x=-x;putchar('-');}
	int y=0;char z[40];
	while(x||!y){z[y++]=x%10+48;x/=10;}
	while(y--)putchar(z[y]);if(ch!='\0')putchar(ch);
}
bool Mbg;
const int maxn=15,maxm=16384,maxt=205,inf=0x3f3f3f3f;
const long long llinf=0x3f3f3f3f3f3f3f3f;
int n,m;
int dis[maxn][maxn];
int f[maxn][maxm][maxt],g[maxn][maxm][maxt];
int q[maxn],d[maxn];
int t[maxn][maxt],w[maxn][maxt];
void ckmx(int &x,int y){x=x>y?x:y;}
void solve_the_problem(){
	n=rd(),m=rd();
	mem(dis,0x3f);
	rep(i,1,n)dis[i][i]=0;
	rep(i,1,m){
		int x=rd(),y=rd(),z=rd();
		dis[x][y]=dis[y][x]=min(dis[x][y],z);
	}
	rep(k,1,n)rep(i,1,n)rep(j,1,n)dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	rep(i,1,n)q[i]=rd();
	rep(i,1,n){
		d[i]=rd();
		rep(j,1,d[i])t[i][j]=rd();
		rep(j,1,d[i]+1)w[i][j]=rd();
		t[i][d[i]+1]=inf;
	}
	mem(f,0xc0),mem(g,0xc0);
	rep(i,1,n){
		int tim=min(max(dis[1][i],q[i]),201ll),p=1;
		rep(j,tim,201){
			while(t[i][p]<=j)p++;
			f[i][1<<(i-1)][j]=w[i][p];
			g[i][1<<(i-1)][j]=max(g[i][1<<(i-1)][j-1],f[i][1<<(i-1)][j]);
		}
	}
	rep(S,1,(1<<n)-1){
		rep(i,1,n)if(!(S&(1<<(i-1)))){
			int p=1;
			rep(ed,q[i],200){
				while(t[i][p]<=ed)p++;
				rep(j,1,n)if(S&(1<<(j-1))){
					if(ed-dis[i][j]>=0)ckmx(f[i][S|(1<<(i-1))][ed],g[j][S][ed-dis[i][j]]+w[i][p]);
				}
				g[i][S|(1<<(i-1))][ed]=max(g[i][S|(1<<(i-1))][ed-1],f[i][S|(1<<(i-1))][ed]);
			}
			rep(j,1,n)if(S&(1<<(j-1))){
				ckmx(f[i][S|(1<<(i-1))][201],g[j][S][201]+w[i][d[i]+1]);
			}
			g[i][S|(1<<(i-1))][201]=max({g[i][S|(1<<(i-1))][200],f[i][S|(1<<(i-1))][201]});
		}
	}
	int ans=0;
	rep(i,1,n)rep(j,0,201)ckmx(ans,f[i][(1<<n)-1][j]);
	write(ans);
}
bool Med;
signed main(){
//	freopen(".in","r",stdin);freopen(".out","w",stdout);
//	fprintf(stderr,"%.3lfMB\n",(&Mbg-&Med)/1048576.0);
	int _=1;while(_--)solve_the_problem();
}
/*
3 2
1 2 1
2 3 1
1 3 3
1
2
5 1
1
4
5 4
1
4
5 1
*/

作者:dcytrl

出处:https://www.cnblogs.com/dcytrl/p/17994167

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   dcytrl  阅读(10)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
more_horiz
keyboard_arrow_up light_mode palette
选择主题
点击右上角即可分享
微信分享提示