UVA 10985 Rings'n'Ropes
最短路 参考了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的更多相关文章
- 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 ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- 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 ...
- UVA - 1625 Color Length[序列DP 代价计算技巧]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
随机推荐
- POJ:2377-Bad Cowtractors
传送门:http://poj.org/problem?id=2377 Bad Cowtractors Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- Hibernate---数据操作示例BY实体映射文件
创建一个Student.java类:该类需要一个无参的构造函数,以及属性的get/set方法 public class Student implements Serializable { privat ...
- Toolbar中menu菜单文字颜色的修改
Toolbar菜单中menu当中我们大多数都使用图片来按钮,可是有些时候我们也会直接使用文字,文字的颜色如何修改呢. 其实很简单,我们只要修改styles.xml文件中,添加一句 <item n ...
- static关键字什么意思?Java中是否可以覆盖一个private或者是static的方法?
答案:“static”关键字表明一个成员变量或者是成员方法可以在没有所属的类的实例变量的情况下被访问.Java中static方法不能被覆盖,因为方法覆盖是基于运行时动态绑定的,而static方法是编译 ...
- Java架构师必会的技能
Java架构师必会的技能 我把它分为了五大专题 工程化专题 工程化专题 git git安装使用 git日常使用:fetch/pull/push/revert/rebase git分支管理git flo ...
- shell判断文件是否存在[转]
原文出处: http://canofy.iteye.com/blog/252289 shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/htt ...
- MySQL高可用之MHA安装
Preface MasterHA is a tool which can be used in MySQL HA architecture.I'm gonna implement it ...
- NOIP2018 集训(三)
A题 Tree 问题描述 给定一颗 \(n\) 个点的树,树边带权,试求一个排列 \(P\) ,使下式的值最大 \[\sum_{i=1}^{n-1} maxflow(P_i, P_{i+1}) \] ...
- ehcache + spring 整合以及配置说明 ,附带整合问题 (已解决)
新做的项目,因为流量不大 就是一个征信平台,高峰流量不多,但缓存是必须的,cache到server上就可以,不需要额外的memcache.redis之类的东西. 但是遇到一个大坑,事情是这样的: 通过 ...
- 参加2018之江杯全球人工智能大赛
:视频识别&问答
学习了一段时间的AI,用天池大赛来检验一下自己的学习成果. 题目:参赛者需对给定的短视频进行内容识别和分析,并回答每一个视频对应的问题.细节请到阿里天池搜索. 两种思路 1 将视频截成一帧一帧的图片, ...