uva-539-枚举
题意:
给你一个无向图,找最长路.
俩份代码,感觉map[][]简单易懂啊
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<queue>
#include<map>
#include<memory.h>
#include <math.h>
#include<time.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define N 26
int n, m;
int mp = -;
struct Edge
{
int num;
int s;
int e;
}; int nn[N][N];
int ni[N];
Edge edges[N];
int vis[N];
int dfs(int cn, int cur)
{
for(int i = ; i < ni[cn]; i++)
{
if(vis[nn[cn][i]])
continue;
Edge edge = edges[nn[cn][i]];
int e = edge.e == cn ? edge.s : edge.e;
vis[nn[cn][i]] = ;
dfs(e, cur + );
vis[nn[cn][i]] = ;
}
mp = mp < cur ? cur : mp;
return cur;
}
int main(const int argc, char** argv)
{
//freopen("d:\\1.txt", "r", stdin);
while (cin >> n >> m && (n && m))
{
memset(vis, , sizeof(vis));
memset(nn, , sizeof(nn));
memset(ni, , sizeof(ni));
for(int i = ; i < m; i++)
{
Edge edge;
edge.num = i;
cin >> edge.s >> edge.e;
edges[i] = edge;
nn[edge.s][ni[edge.s]++] = i;
nn[edge.e][ni[edge.e]++] = i;
}
for(int i = ; i < n; i++)
{
dfs(i, );
}
cout << mp << endl;
mp = ;
}
return ;
}
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<queue>
#include<map>
#include<memory.h>
#include <math.h>
#include<time.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define N 30
int n, m;
int mp = -; int nn[N][N];
int dfs(int cn, int cur)
{
for(int i = ; i < n; i++)
{
if(nn[cn][i])
{
nn[cn][i]--;
nn[i][cn]--;
dfs(i, cur + );
nn[cn][i]++;
nn[i][cn]++;
} }
mp = mp < cur ? cur : mp;
return cur;
}
int main(const int argc, char** argv)
{
//freopen("d:\\1.txt", "r", stdin);
while (cin >> n >> m )
{
if(n==&&m==)
return ;
memset(nn, , sizeof(nn));
mp = ;
int s, e;
for(int i = ; i < m; i++)
{
cin >> s >> e;
nn[s][e]++;
nn[e][s]++;
}
for(int i = ; i < n; i++)
{
dfs(i, );
}
cout << mp << endl;
}
return ;
}
uva-539-枚举的更多相关文章
- UVa 12169 (枚举+扩展欧几里得) Disgruntled Judge
题意: 给出四个数T, a, b, x1,按公式生成序列 xi = (a*xi-1 + b) % 10001 (2 ≤ i ≤ 2T) 给出T和奇数项xi,输出偶数项xi 分析: 最简单的办法就是直接 ...
- UVa 140 (枚举排列) Bandwidth
题意较复杂,请参见原题=_=|| 没什么好说的,直接枚举每个排列就好了,然后记录最小带宽,以及对应的最佳排列. STL里的next_permutation函数真是好用. 比较蛋疼的就是题目的输入了.. ...
- UVa 1151 (枚举 + MST) Buy or Build
题意: 平面上有n个点,现在要把它们全部连通起来.现在有q个套餐,如果购买了第i个套餐,则这个套餐中的点全部连通起来.也可以自己单独地建一条边,费用为两点欧几里得距离的平方.求使所有点连通的最小费用. ...
- Even Parity UVA - 11464 (枚举)
从来没有觉得枚举有多费脑子的.但是这道题还是很香的. 思路:就是非常简单的枚举啦. 从一般的枚举开始考虑.一般的做法就是在所有的格子中有两种状态1, 0. 而一共有225个格子,所有一共要枚举的情 ...
- UVa 1354 枚举子集 Mobile Computing
只要枚举左右两个子天平砝码的集合,我们就能算出左右两个悬挂点到根悬挂点的距离. 但是题中要求找尽量宽的天平但是不能超过房间的宽度,想不到要怎样记录结果. 参考别人代码,用了一个结构体的vector,保 ...
- UVA 539 The Settlers of Catan dfs找最长链
题意:画边求最长链,边不能重复数点可以. 很水,用暴力的dfs即可,因为数据不大. 本来以为可以用floyd进行dp的,后来想想好像不能在有回路上的图跑...于是没去做. #include <c ...
- Uva 11754(枚举+中国剩余定理)
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #inclu ...
- 10年省赛-Greatest Number (二分+暴力) + 12年省赛-Pick apples(DP) + UVA 12325(暴力-2次枚举)
题意:给你n个数,在里面取4个数,可以重复取数,使和不超过M,求能得到的最大的数是多少: 思路:比赛时,和之前的一个题目很像,一直以为是体积为4(最多选择四次)的完全背包,结果并不是,两两求和,然后二 ...
- UVa 10465 Homer Simpson (枚举)
10465 - Homer Simpson Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...
- uva 11825 Hackers' Crackdown (状压dp,子集枚举)
题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪( ...
随机推荐
- [LeetCode&Python] Problem 700. Search in a Binary Search Tree
Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST ...
- 内网渗透中SSh的巧用
后续应该会做个实例 转自:http://www.myhack58.com/Article/html/3/8/2009/25156.htm 经常遇到如下情形,内部网络主机通过路由器或者安全设备做了访问控 ...
- CF1142E/1143B Lynyrd Skynyrd
CF1142E/1143B Lynyrd Skynyrd 开始读错题了,以为是连续的一段,敲完后才发现是 \(subsequence\) ... 考虑对于 \(a\) 中的每个 \(a_i\) 找到它 ...
- CSU 1112: 机器人的指令
1112: 机器人的指令 Submit Page Description 数轴原点有一个机器人.该机器人将执行一系列指令,你的任务是预测所有指令执行完毕之后它的位置. ·LEFT:往 ...
- laravel5.3 源码分析 Passport
laravel5.3,密码模式的授权认证过程.我会通过两部分内容分享以及查看passport的认证流程分享出来 第一部分:根据官方文档,通过Composer安装Passport 文档地址:http:/ ...
- MySQL--修改表字段
##========================================================================## ## 修改表字段 ## CHANGE和MODI ...
- memsql 6.7集群安装
预备环境处理 安装yum 源 yum install -y yum-utils yum-config-manager --add-repo https://release.memsql.com/pro ...
- 让node支持es模块化(export、import)的方法
node版本v7.9.0,支持了大部分es6的功能,但还不支持es6模块化(export.import). 检测ES6 可以使用es-checker来检测当前Node.js对ES6的支持情况. 使用命 ...
- nginx 官方docker镜像使用教程
最近在看nignx,在本地虚拟机使用docker nginx镜像搭建了nginx+php环境 整理的教程如下: 拉取nginx镜像docker pull nginx 创建一个容器,并挂载本地目录doc ...
- Angular 4 表单
一. 模板表单 1. 如下图 2. code 3. 效果图 二.响应式表单 1. 增加ReactiveFormsModule 2.响应式表单用到的类和指令 3. 控制器代码 4. html <! ...