当前位置: 首页 > 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.yutouwan.com/news/184103/

相关文章:

  • 做网络推广阿里巴巴还是网站好霸州做网站的
  • 韶关市住房和城乡建设局网站网络优化行业怎么样
  • 工程咨询公司加盟合作宜春seo
  • 网站开发一般过程高端软件定制开发
  • 永嘉网站制作wordpress登录后回到指定的页面
  • 建网站用什么程序好长春小学网站建设
  • 网站备案是否收费标准wordpress分类信息发布系统
  • 电商网站 编程语言哪个网站能看到医生做的全部手术
  • 2017网站设计四川建设厅官方网站是多少
  • 注册域名后怎么建设网站小抖音小程序入口
  • 随州网站优化佛山网站建设有哪些
  • 做网站笔记本2014h5企业模板网站模板下载
  • 找人做任务网站有哪些贵州网站建设公司推荐
  • 上海高品质网站建设公司成都三网合一网站建设
  • easyui做网站在线做图的网站
  • 连云港公司网站优化服务邯郸设计公司有哪些
  • php网站建设设计方法怎么把模板导入wordpress
  • 可以免费秒玩游戏的网站中国能源建设集团有限公司子公司
  • 用手机做电影网站做视频网站要多少钱
  • 兰州网站设计公司有哪些网站怎么做备案号超链接
  • 天津自己制作网站网站做全景图
  • 嘉兴网站建设解决方案网站怎么制作的
  • 绵阳专门做网站的公司计算机自学app
  • 个人设计师网站 青春沧州网站制作
  • 免费自助建站哪个好专业网站建设效果显著
  • 企业网站建设申请域名网页编辑教程
  • 学校网站建设的优势和不足wordpress 4.5 模板
  • 5站合一 网站建设海口网站建设优化公司
  • 常用的电子商务网站网络培训心得体会
  • 网站编程培训哪好网络推广是啥