最短路 参考了Staingger的博客

感觉DP的状态记录还是有毛病。可以DFS寻找结果也。

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <cmath>
  5. #include <ctime>
  6. #include <deque>
  7. #include <stack>
  8. #include <queue>
  9. #include <cctype>
  10. #include <cstdio>
  11. #include <string>
  12. #include <vector>
  13. #include <climits>
  14. #include <cstdlib>
  15. #include <cstring>
  16. #include <iostream>
  17. #include <algorithm>
  18. #define LL long long
  19. #define PI 3.1415926535897932626
  20. using namespace std;
  21. int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
  22. #define MAXN 150
  23. const int INF = 0x3f3f3f3f ;
  24. int dp[MAXN][MAXN];
  25. bool vis[MAXN][MAXN];
  26. int N,M,ans;
  27. void init()
  28. {
  29. scanf("%d%d",&N,&M);
  30. memset(dp,0x3f,sizeof(dp));
  31. while (M--)
  32. {
  33. int u,v;
  34. scanf("%d%d",&u,&v);
  35. dp[u][v] = dp[v][u] = ;
  36. }
  37. for (int k = ; k < N; k++)
  38. for (int i = ; i < N; i++)
  39. for (int j = ; j < N; j++)
  40. dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j]);
  41. for (int i = ; i < N; i++) dp[i][i] = ;
  42. }
  43. int calcu(int s, int t)
  44. {
  45. int res[MAXN],cas = ,cnt = ;
  46. for (int k = ; k < N; k++)
  47. if (dp[s][k] + dp[k][t] == dp[s][t]) res[cas++] = k;
  48. for (int i = ; i < cas; i++)
  49. for (int j = i + ; j < cas; j++)
  50. {
  51. int a = res[i] , b = res[j];
  52. if(dp[a][b] == && dp[s][a] != dp[s][b])
  53. cnt++;
  54. }
  55. return cnt;
  56. }
  57. void slove()
  58. {
  59. for (int i = ; i < N; i++)
  60. for (int j = i + ; j < N; j++)
  61. {
  62. if (dp[i][j] != INF)
  63. ans = max(ans,calcu(i,j));
  64. }
  65. }
  66. int main()
  67. {
  68. //freopen("sample.txt","r",stdin);
  69. int T,kase = ;
  70. scanf("%d",&T);
  71. while (T--)
  72. {
  73. init();
  74. ans = ;
  75. slove();
  76. printf("Case #%d: %d\n",kase++,ans);
  77. }
  78. return ;
  79. }

UVA 10985 Rings'n'Ropes的更多相关文章

  1. UVA 10985 - Rings'n'Ropes(floyd)

    Problem D Rings'n'Ropes Time Limit: 3 seconds "Well, that seems to be the situation. But, I don ...

  2. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  3. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  4. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  5. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  6. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  7. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

  8. UVA数学入门训练Round1[6]

    UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...

  9. UVA - 1625 Color Length[序列DP 代价计算技巧]

    UVA - 1625 Color Length   白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束   和模拟赛那道环形DP很想,计算这 ...

随机推荐

  1. POJ:2377-Bad Cowtractors

    传送门:http://poj.org/problem?id=2377 Bad Cowtractors Time Limit: 1000MS Memory Limit: 65536K Total Sub ...

  2. Hibernate---数据操作示例BY实体映射文件

    创建一个Student.java类:该类需要一个无参的构造函数,以及属性的get/set方法 public class Student implements Serializable { privat ...

  3. Toolbar中menu菜单文字颜色的修改

    Toolbar菜单中menu当中我们大多数都使用图片来按钮,可是有些时候我们也会直接使用文字,文字的颜色如何修改呢. 其实很简单,我们只要修改styles.xml文件中,添加一句 <item n ...

  4. static关键字什么意思?Java中是否可以覆盖一个private或者是static的方法?

    答案:“static”关键字表明一个成员变量或者是成员方法可以在没有所属的类的实例变量的情况下被访问.Java中static方法不能被覆盖,因为方法覆盖是基于运行时动态绑定的,而static方法是编译 ...

  5. Java架构师必会的技能

    Java架构师必会的技能 我把它分为了五大专题 工程化专题 工程化专题 git git安装使用 git日常使用:fetch/pull/push/revert/rebase git分支管理git flo ...

  6. shell判断文件是否存在[转]

    原文出处: http://canofy.iteye.com/blog/252289 shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/htt ...

  7. MySQL高可用之MHA安装

      Preface       MasterHA is a tool which can be used in MySQL HA architecture.I'm gonna implement it ...

  8. NOIP2018 集训(三)

    A题 Tree 问题描述 给定一颗 \(n\) 个点的树,树边带权,试求一个排列 \(P\) ,使下式的值最大 \[\sum_{i=1}^{n-1} maxflow(P_i, P_{i+1}) \] ...

  9. ehcache + spring 整合以及配置说明 ,附带整合问题 (已解决)

    新做的项目,因为流量不大 就是一个征信平台,高峰流量不多,但缓存是必须的,cache到server上就可以,不需要额外的memcache.redis之类的东西. 但是遇到一个大坑,事情是这样的: 通过 ...

  10. 参加2018之江杯全球人工智能大赛
:视频识别&问答

    学习了一段时间的AI,用天池大赛来检验一下自己的学习成果. 题目:参赛者需对给定的短视频进行内容识别和分析,并回答每一个视频对应的问题.细节请到阿里天池搜索. 两种思路 1 将视频截成一帧一帧的图片, ...