日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

深海机器人问题

發(fā)布時間:2025/3/20 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 深海机器人问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目描述

題解:

最大費(fèi)用最大流。

建圖很簡單,就是將機(jī)器人作為流,進(jìn)入就從$S$向內(nèi)流,出來就從圖向$T$流。

代碼:

#include<queue> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define N 300 #define ll long long const int inf = 0x3f3f3f3f; const ll Inf = 0x3f3f3f3f3f3f3f3fll; inline int rd() {int f=1,c=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){c=10*c+ch-'0';ch=getchar();}return f*c; } int a,b,P,Q,S,T,hed[N],cnt=-1; int _id(int x,int y){return x*(Q+1)+y;} struct EG {int to,nxt;ll w,c; }e[10*N]; void ae(int f,int t,ll w,ll c) {e[++cnt].to = t;e[cnt].nxt = hed[f];e[cnt].w = w;e[cnt].c = c;hed[f] = cnt; } queue<int>q; ll dis[N],fl[N]; int pre[N],fa[N]; bool vis[N]; bool spfa() {memset(dis,0x3f,sizeof(dis));dis[S] = 0,fl[S] = Inf,vis[S] = 1;q.push(S);while(!q.empty()){int u = q.front();q.pop();for(int j=hed[u];~j;j=e[j].nxt){int to = e[j].to;if(e[j].w&&dis[to]>dis[u]+e[j].c){dis[to] = dis[u]+e[j].c;fl[to] = min(fl[u],e[j].w);pre[to] = j,fa[to] = u;if(!vis[to]){vis[to] = 1;q.push(to);}}}vis[u] = 0;}return dis[T]!=Inf; } ll mcmf() {ll ret = 0;while(spfa()){ret+=fl[T]*dis[T];int u = T;while(u!=S){e[pre[u]].w-=fl[T];e[pre[u]^1].w+=fl[T];u=fa[u];}}return ret; } int main() {a = rd(),b = rd(),P = rd(),Q = rd();memset(hed,-1,sizeof(hed));for(int i=0;i<=P;i++)for(int c,j=0;j<Q;j++){int f = _id(i,j);int t = _id(i,j+1);c = rd();ae(f,t,1,-c);ae(t,f,0,c);ae(f,t,Inf,0);ae(t,f,0,0);}for(int i=0;i<=Q;i++)for(int c,j=0;j<P;j++){int f = _id(j,i);int t = _id(j+1,i);c = rd();ae(f,t,1,-c);ae(t,f,0,c);ae(f,t,Inf,0);ae(t,f,0,0); }S = _id(P,Q)+1,T = S+1;for(int w,x,y,i=1;i<=a;i++){w = rd(),x = rd(),y = rd();int t = _id(x,y);ae(S,t,w,0);ae(t,S,0,0);}for(int w,x,y,i=1;i<=b;i++){w = rd(),x = rd(),y = rd();int f = _id(x,y);ae(f,T,w,0);ae(T,f,0,0);}printf("%lld\n",-mcmf());return 0; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/LiGuanlin1124/p/10255940.html

總結(jié)

以上是生活随笔為你收集整理的深海机器人问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。