UVA 12377 Number Coding --DFS】的更多相关文章

题意:给一串数字,第一个数是Num的话,要使后面的数字组成Num个数,而且为不降的,将这Num个数分配到9个素因子上作为指数,问能组成多少个不同的数 解法:dfs一遍,看后面的数字能组成Num个不降数字的方法种数,及该种方法的不同数字的个数,然后这些方法加起来.具体见代码吧. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <a…
题目:一个数能够用一种素数元素的个数表示的形式,43560=23×32×51×112表示成41223: 第一个数是素因子的种类,第二个是每一个素因子的个数递增排列.给你一个这样的形式的串, 问原来的数可能有几种情况. 分析:数论,计数原理,组合数学. 对于每一个串,第一个数字一定是素因子的种类数. 首先,利用搜索找到全部剩余串的可能组合形式. 然后.求出每种情况下的组合数.加和就可以. 说明:注意一个新的数字不能以0開始. #include <iostream> #include <cs…
UVA 1558 - Number Game 题目链接 题意:20之内的数字,每次能够选一个数字,然后它的倍数,还有其它已选数的倍数组合的数都不能再选,谁先不能选数谁就输了,问赢的方法 思路:利用dp记忆化去求解,要输出方案就枚举第一步就可以,状态转移过程中,选中一个数字,对应的变化写成一个函数,然后就是普通的博弈问题了,必胜态之后必有必败态,必败态之后全是必胜态 代码: #include <stdio.h> #include <string.h> const int N = 10…
UVA - 11853 思路:dfs,从最上面超过上边界的圆开始搜索,看能不能搜到最下面超过下边界的圆. 代码: #include<bits/stdc++.h> using namespace std; ; double l,r; int n; bool vis[N]={false}; bool flag=false; struct point { int x,y,r; }a[N]; bool intersect(point a,point b) { return (a.x-b.x)*(a.x…
UVA.548 Tree(二叉树 DFS) 题意分析 给出一棵树的中序遍历和后序遍历,从所有叶子节点中找到一个使得其到根节点的权值最小.若有多个,输出叶子节点本身权值小的那个节点. 先递归建树,然后DFS求解. 代码总览 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <sstre…
题目连接:uva 11885 - Number of Battlefields 题目大意:给出周长p,问多少种形状的周长为p的,而且该图形的最小包围矩阵的周长也是p,不包含矩形. 解题思路:矩阵高速幂.假设包括矩形的话,相应的则是斐波那契数列的偶数项,所以相应减去矩形的个数就可以. #include <cstdio> #include <cstring> using namespace std; typedef long long ll; const ll MOD = 987654…
题目 题目     分析 典型搜索,考虑剪枝. 统计一下联通分量. 1.本位置能够达到所有的点的数量加上本已有的点,还没有之前的结果长,直接返回. 2.当本位置能够达到所有的点的数量加上本已有的点与之前的结果一样长,就把联通分量里的点从大到小排序.如果这样都比Ans小,那么直接返回. 前两种是大多人用的,这两个剪枝有了,AC不是问题. 3.如果本图没有障碍物,那么意味着所有点联通,那么结果必定是从整张图的最大值出发的,非最大值,就不用考虑了. 这个是我自己想的,大约能剪 40-80 ms. 个人…
UVA - 1103Ancient Messages In order to understand early civilizations, archaeologists often study texts written in ancient languages.One such language, used in Egypt more than 3000 years ago, is based on characters called hieroglyphs.Figure C.1 shows…
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=513 终于开始接触图了,恩,开始接触DFS了,这道题就是求连通分量,比较简单. #include<iostream> #include<cstring> using namespace std; int m, n; //记录连通块的数量 ][]; ][]; void…
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It…