当前位置: 首页 > news >正文

购物网站建设 费用网站制作潍坊

购物网站建设 费用,网站制作潍坊,装潢设计与工艺教育专业,帮别人做钓鱼网站犯法吗题意#xff1a; N个城市#xff0c;编号1到N。城市间有R条单向道路。有长度和过路费两个属性。Bob只有K块钱#xff0c;他想从城市1走到城市N。问最短共需要走多长的路。如果到不了N#xff0c;输出-1。 题目#xff1a; N cities named with numbers 1 … N are conn…题意 N个城市编号1到N。城市间有R条单向道路。有长度和过路费两个属性。Bob只有K块钱他想从城市1走到城市N。问最短共需要走多长的路。如果到不了N输出-1。 题目 N cities named with numbers 1 … N are connected with one-way roads. Each road has two parameters associated with it : the road length and the toll that needs to be paid for the road (expressed in the number of coins). Bob and Alice used to live in the city 1. After noticing that Alice was cheating in the card game they liked to play, Bob broke up with her and decided to move away - to the city N. He wants to get there as quickly as possible, but he is short on cash. We want to help Bob to find the shortest path from the city 1 to the city N that he can afford with the amount of money he has. Input The first line of the input contains the integer K, 0 K 10000, maximum number of coins that Bob can spend on his way. The second line contains the integer N, 2 N 100, the total number of cities. The third line contains the integer R, 1 R 10000, the total number of roads. Each of the following R lines describes one road by specifying integers S, D, L and T separated by single blank characters : S is the source city, 1 S N D is the destination city, 1 D N L is the road length, 1 L 100 T is the toll (expressed in the number of coins), 0 T 100 Notice that different roads may have the same source and destination cities. Output The first and the only line of the output should contain the total length of the shortest path from the city 1 to the city N whose total toll is less than or equal K coins. If such path does not exist, only number -1 should be written to the output. Sample Input 5 6 7 1 2 2 3 2 4 3 3 3 4 2 4 1 3 4 1 4 6 2 1 3 5 2 0 5 4 3 2 Sample Output 11 分析 给了n个城市需要从城市1到城市n,求最短距离要是这样就是一道简单的最短路问题但题目有限制要求在满足花费即不超过k的情况下的最短路 1.首先考虑得用搜索迭代寻找在找到所有满足路径后选出最短的注意剪枝。 2.选用邻接表来存储无向图的时间空间复杂度是O(M)。 如果只是查询两个点之间是否相邻,邻接矩阵当然更快,但如果是做dfs的话,找当前节点相邻的点,如果用邻接矩阵的话每次都要从1扫到n,如果用邻接表遍历每个顶点的边 AC代码 #includestdio.h #includestring.h #includealgorithm using namespace std; typedef long long ll; const int inf0x3f3f3f3f; const int M1e410; int n,m,k; ll ans; int a[M],b[M],c[M],d[M],fir[M],nex[M],book[M]; void dfs(int x/*当前到达城市*/,int y/*费用*/,int z/*路程*/) {if(yn||zans)return ;if(xm){ansz;return ;}for(int ifir[x];i;inex[i])if(!book[i]){book[i]1;dfs(b[i],yd[i],zc[i]);book[i]0;}return ; } int main() {scanf(%d%d%d,n,m,k);for(int i1;ik;i)/*care 变量要从1开始邻接表定义*/{scanf(%d%d%d%d,a[i],b[i],c[i],d[i]);nex[i]fir[a[i]];fir[a[i]]i;}ansinf;dfs(1,0,0);if(ansinf) printf(-1\n);else printf(%lld\n,ans);return 0; }
http://www.huolong8.cn/news/184103/

相关文章:

  • ps做登录网站河北承德网
  • 网站开发什么技术路线网站根目录表示
  • 网站内容怎么做备份互联网一线大厂排名
  • 制作注册会员的网站深圳产品设计公司排名前十强
  • 厂房建设招标网站优秀网页设计作品文字分析
  • 四川省建设局网站电子商务做网站设计
  • 如何做网站的注册页面厦门网站开发培训
  • 做直播 网站的上市公司首选大型网站建站公司
  • 培训网站模板韦博在上面做课件的网站叫什么
  • 台州cms建站系统建筑工程公司有哪些岗位
  • 网站手机端怎么制作教程微信小程序怎么盈利
  • 湘潭网站设计公司装潢设计专业可以考二建吗
  • 昆明建设局网站号码网站登录后不显示内容
  • 那种网站打不开经典网页设计欣赏
  • 上海长宁区网站建设wordpress 添加链接
  • 彬县网站wordpress邮箱插件
  • 建设网站系统wordpress求助
  • 宁夏网站建设怎么样静态网站开发课程模板
  • 国外的网站建设wordpress投稿系统
  • 大理高端网站建设友点cms
  • 网站开发询价方案业之峰装饰公司简介
  • 深圳成交型网站建设石景山网站建设有哪些公司
  • 秦皇岛网站制作小程序开发开发平台 英文
  • 北京网站建设搜q.479185700定制营销型网站公司
  • 雁塔免费做网站验证码平台 wordpress
  • 保定网站制作软件网站改版怎样做301
  • 什么网站做顶置便宜温州网站制作网站
  • 怎么下载网站备案号网站开发网页前置开发
  • 怎么用eclipse做网站开发郑州网站建设乛汉狮网络
  • 网站建设 jz.woonl网站速度