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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

牛客 NC24858 [USACO 2009 Nov S]Job Hunt

發布時間:2023/12/20 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 牛客 NC24858 [USACO 2009 Nov S]Job Hunt 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述

Bessie is running out of money and is searching for jobs. Farmer John knows this and wants the cows to travel around so he has imposed a rule that his cows can only make D (1 <= D <= 1,000) dollars in a city before they must work in another city. Bessie can, however, return to a city after working elsewhere for a while and again earn the D dollars maximum in that city. There is no limit on the number of times Bessie can do this.
Bessie's world comprises P (1 <= P <= 150) one-way paths connecting C (2 <= C <= 220) cities conveniently numbered 1..C. Bessie is currently in city S (1 <= S <= C). Path i runs one-way from city Ai to city Bi (1 <= Ai <= C; 1 <= Bi <= C) and costs nothing to traverse.
To help Bessie, Farmer John will give her access to his private jet service. This service features F (1 <= F <= 350) routes, each of which is a one way flight from one city Ji to a another Ki (1 <= Ji <= C; 1 <= Ki <= C) and which costs Ti (1 <= Ti <= 50,000) dollars. Bessie can pay for the tickets from future earnings if she doesn't have the cash on hand.
Bessie can opt to retire whenever and wherever she wants. Given an unlimited amount of time, what is the most money that Bessie can make presuming she can make the full D dollars in each city she can travel to? Print -1 if there is no limit to this amount.

輸入描述:

* Line 1: Five space-separated integers: D, P, C, F, and S * Lines 2..P+1: Line i+1 contains two space-separated integers that name a one-way path from one city to another: Ai and Bi * Lines P+2..P+F+1: Line P+i+1 contains three space-separated integers that name a one-way jet flight from one city to another and the price for that flight: Ji, Ki, and Ti

輸出描述:

* Line 1: A single integer representing the most money she can make while following the law.

示例1

輸入

復制

100 3 5 2 1 1 5 2 3 1 4 5 2 150 2 5 120

輸出

復制

250

說明

This world has five cities, three paths and two jet routes. Bessie starts out in city 1, and she can only make 100 dollars in each city before moving on. Bessie can travel from city 1 to city 5 to city 2 to city 3, and make a total of 4*100 - 150 = 250 dollars.

思路:這是一道比較裸的最長路問題,只要將起點的距離初始化為d,建圖時兩點之間的路徑距離為d,航線距離為d-c;

AC代碼:

#include<iostream> #include<cstring> #include<cstdio> #include<queue> using namespace std;const int N=230,M=100010;int h[N],ne[M],e[M],w[M],idx; int d,m,n,f,s; int dist[N]; bool st[N];void add(int a,int b,int c) {e[idx]=b,w[idx]=c,ne[idx]=h[a],h[a]=idx++; }void spfa() {memset(dist,-0x3f,sizeof dist);queue<int> q;dist[s]=d;q.push(s);while(q.size()){int t=q.front();q.pop();st[t]=0;for(int i=h[t];~i;i=ne[i]){int j=e[i];if(dist[j]<dist[t]+w[i]){dist[j]=dist[t]+w[i];if(!st[j]){q.push(j);st[j]=1;}}}} }int main() {memset(h,-1,sizeof h);scanf("%d%d%d%d%d",&d,&m,&n,&f,&s);while(m--){int a,b;cin>>a>>b;add(a,b,d);}while(f--){int a,b,c;cin>>a>>b>>c;add(a,b,d-c);}spfa();int res=-0x3f3f3f3f;for(int i=1;i<=n;i++)res=max(res,dist[i]);cout<<res; }

總結

以上是生活随笔為你收集整理的牛客 NC24858 [USACO 2009 Nov S]Job Hunt的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。