最短路 参考了Staingger的博客

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

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
#define MAXN 150
const int INF = 0x3f3f3f3f ;
int dp[MAXN][MAXN];
bool vis[MAXN][MAXN];
int N,M,ans;
void init()
{
scanf("%d%d",&N,&M);
memset(dp,0x3f,sizeof(dp));
while (M--)
{
int u,v;
scanf("%d%d",&u,&v);
dp[u][v] = dp[v][u] = ;
}
for (int k = ; k < N; k++)
for (int i = ; i < N; i++)
for (int j = ; j < N; j++)
dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j]);
for (int i = ; i < N; i++) dp[i][i] = ;
}
int calcu(int s, int t)
{
int res[MAXN],cas = ,cnt = ;
for (int k = ; k < N; k++)
if (dp[s][k] + dp[k][t] == dp[s][t]) res[cas++] = k;
for (int i = ; i < cas; i++)
for (int j = i + ; j < cas; j++)
{
int a = res[i] , b = res[j];
if(dp[a][b] == && dp[s][a] != dp[s][b])
cnt++;
}
return cnt;
}
void slove()
{
for (int i = ; i < N; i++)
for (int j = i + ; j < N; j++)
{
if (dp[i][j] != INF)
ans = max(ans,calcu(i,j));
}
}
int main()
{
//freopen("sample.txt","r",stdin);
int T,kase = ;
scanf("%d",&T);
while (T--)
{
init();
ans = ;
slove();
printf("Case #%d: %d\n",kase++,ans);
}
return ;
}

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. django-mysqlclient_1193错误

    Django 配置 mysqlclient 驱动 1193错误 错误描述: django.db.utils.OperationalError: (1193, "Unknown system ...

  2. 笔记-爬虫-模拟登录github

    笔记-模拟登录github 1.      模拟登录github 1.1.    环境准备 安装/升级requests 2.20.0 pip install --upgrade requests pi ...

  3. python开发基础之字符编码、文件处理和函数基础

    字符编码 为什么要有字符编码? 字符编码是为了让计算机能识别我们人写的字符,因为计算机只认识高低电平,也就是二进制数"0","1". 一个文件用什么编码方式存储 ...

  4. spark练习--mysql的读取

    前面我们一直操作的是,通过一个文件来读取数据,这个里面不涉及数据相关的只是,今天我们来介绍一下spark操作中存放与读取 1.首先我们先介绍的是把数据存放进入mysql中,今天介绍的这个例子是我们前两 ...

  5. AOP的两种实现方式

    技术交流群 :233513714 AOP,面向切面编程,可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术.    Aspect Oriented Progr ...

  6. FileStream流媒体

    class Program { static void Main(string[] args) { string source = @"mana.mp4"; string targ ...

  7. 初学JS——实现基于计时器的小游戏。

    这几天一直在看网易云课堂上免费的JS课程,正好今天看到讲了计时器setInterval,第一感觉就是像C#里的TIMER.然后课程里举得例子正好通过计时器改变新生成窗口的位置, 然后就突然有了灵感!可 ...

  8. QBASIC教程

    Qbasic 程序设计入门 BASIC(Beginner’s All-purpose Symbolic Instruction Code 的缩写,意为初学者通用符号指令代码)语言是在1964年由美国的 ...

  9. Windows Phone 图片扩展类

    using System.IO; using System.Text; using System.Net; using System.Threading.Tasks; using System.Win ...

  10. 。net可以点出属性,编译没问题,运行时就报错了。一笔记。

    项目框架是这样的. 在 domain(你可以把它理解为你的bll) ,web 2个项目工程里面都引用了一个通过nuget管理程序包,比如 xxcommon.dll web 引用了 domain ,然后 ...