UVA10624 - Super Number(dfs)】的更多相关文章

题目:UVA10624 - Super Number(dfs) 题目大意:给你n和m要求找出这种m位数,从第n位到第m位都满足前i位是能够被i整除,假设没有这种数,输出-1.有多个就输出字典序最小的那个. 解题思路:将每一个位置都用0..9枚举一下,注意第一个字符不能是0,然后dfs推断每一个位置是否都满足要求.注意这里是会爆long long的,所以要取模一下.本来以为这种做法会超时的,结果居然过了,预计是例子数少,并且找不到的情况也比較少. 代码: #include <cstdio> #i…
Problem UVA11882-Biggest Number Accept: 177    Submit: 3117Time Limit: 1000 mSec    Memory Limit : 128MB Problem Description Input There will be at most 25 test cases. Each test begins with two integers R and C (2 ≤ R,C ≤ 15, R∗C ≤ 30), the number of…
题意 Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. 给定数字,输出所有可能的字母组合 解法 可以先将数字对应的字母存好,然后遍历输出就可以.只不过不用递归来写好像比较麻烦,这里用了一个DFS…
题意   把一个数替换为这个数相邻数字差组成的数  知道这个数仅仅剩一位数  若最后的一位数是7  则称原来的数为 July Number  给你一个区间  求这个区间中July Number的个数 从7開始DFS  位数多的数总能由位数小的数推出 #include <bits/stdc++.h> using namespace std; const int N = 1e6; int july[N], n; set<int> ans; int pw[] = {1, 10, 100,…
Biggest Number 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 You have a maze with obstacles and non-zero digits in it: You can start from any square, walk in the maze, and finally stop at some square. Each step, you may only walk into one of the four neighb…
Generalized Palindromic Number Time Limit: 2 Seconds                                     Memory Limit: 65536 KB                             A number that will be the same when it is written forwards or backwards is known as a palindromic number. For…
题目大意 给定两个数n和m,如果长度为m的数满足对于每个i(n<=i<=m),数字的前i位都能被i整除,那么这个数就是超级数,求出字典序最小的符合要求的超级数. 分析 直接暴力搜索 #include<cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespace std;int str[50];int n,m,flag;int judge(int cur){…
B. Smallest number Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem/B Description Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skil…
题目大意:给出一个方格矩阵,矩阵中有数字0~9,任选一个格子为起点,将走过的数字连起来构成一个数,找出最大的那个数,每个格子只能走一次. 题目分析:DFS.剪枝方案:在当前的处境下,找出所有还能到达的点的个数,若当前数字的长度加上个数仍小于目前最优答案的长度,则剪去:若长度相等,则将所有还能到达的数字按从大到小排序后连到当前数字上,如果还比目前最优解小,则减去.找出所有还能到达的点的过程用BFS实现. #pragma comment(linker, "/STACK:1024000000,1024…
题目链接 题意:给出n到m的范围,求出一个数在前i位数组成的数字能被i整除.假设存在输出这个数,假设不存在.输出-1. 思路:回溯,每次放第i位,然后推断是否符合题意.这题踩着时间过去的2.6s(看了下别人的题解.能够降低取模次数来节省时间). 代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const…