有n个珠子,每颗珠子有左右两边两种颜色,颜色有1~50种,问你能不能把这些珠子按照相接的地方颜色相同串成一个环. 可以认为有50个点,用n条边它们相连,问你能不能找出包含所有边的欧拉回路 首先判断是否在一个联通分量中,在判断是否存在欧拉回路,最后输出欧拉回路. #include <stdio.h> #include <string.h> ; <<; int mx,mn,p[maxn],d[maxn],G[maxn][maxn]; int find(int x) { re…
题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=995 Problem D: The Necklace  My little sister had a beautiful necklace made of colorful beads. Two successive beads in the necklace shared a c…
看是否有欧拉回路 有的话打印路径 欧拉回路存在的条件: 如果是有向图的话 1.底图必须是连通图 2.最多有两个点的入度不等于出度 且一个点的入度=出度+1 一个点的入度=出度-1 如果是无向图的话 1.如果这个无向图的连通的 当最多只有两个度数为奇数的点 就一定有欧拉回路 当有两个度数为奇数的点的时候 一个为起点 一个为终点 //============================================================================ // Name…
题目大意: 一个环被切割成了n个小块,每个小块有头尾两个关键字,表示颜色. 目标是判断给出的n个小块能否重构成环,能则输出一种可行解(按重构次序输出n个色块的头尾颜色).反之输出“some beads may be lost”. 解题思路: 一开始想的曼哈顿回路,WA了.后来依靠别人的智慧,知道正解是欧拉回路. 在知道这道题是欧拉回路的情况下就变得很简单了,就是一道模板题……每种颜色看成一个点,每个小块代表两点之间连接的边,如果存在欧拉回路就有可行解. 不存在欧拉回路有两种情况:1.图不连通,2…
uva 紫书例题,这个区间dp最容易错的应该是(S)这种匹配情况,如果不是题目中给了提示我就忽略了,只想着左右分割忘记了这种特殊的例子. dp[i][j]=MIN{dp[i+1][j-1] | if(match(i,j) , dp[i][k]+dp[k+1][j] | i<=k<=j .}注意初始化dp[i][i]=1,表示1个字符最少需要一个才能匹配,dp[i+1][i]=0,因为可能只有两个字符使得i+1>j-1,我们可以认为中间是空字符已经匹配了. 打印路径利用了递归,很巧妙,lr…
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<ctype.h> #include<algorithm> #define N 1010 using namespace std; int dp[N], path[N][N], w[N]; int main() { int v, n; while(~scanf("%d", &v)) { sca…
  Compromise  In a few months the European Currency Union will become a reality. However, to join the club, the Maastricht criteria must be fulfilled, and this is not a trivial task for the countries (maybe except for Luxembourg). To enforce that Ger…
The Necklace  My little sister had a beautiful necklace made of colorful beads. Two successive beads in the necklace shared a common color at their meeting point. The figure below shows a segment of the necklace: But, alas! One day, the necklace was…
My little sister had a beautiful necklace made of colorful beads. Two successive beads in the necklace shared a common color at their meeting point. The figure below shows a segment of the necklace: But, alas! One day, the necklace was torn and the b…
本文链接:http://www.cnblogs.com/Ash-ly/p/5405904.html 题意: 妹妹有一条项链,这条项链由许多珠子串在一起组成,珠子是彩色的,两个连续的珠子的交汇点颜色相同,也就是对于相邻的两个珠子来说,前一个珠子的末端颜色和后一个珠子的首端颜色相同.有一天,项链断了,珠子洒落了一地,到处都是,妹妹使出浑身解数把地板上能看到的珠子(5-1000)都捡了起来,但是不确定是否收集齐了.给你他妹妹收集的珠子的两端的颜色编号(1 - 50),让你判断是否收集齐了. 思路: 把…