【UVa】439 Knight Moves(dfs)】的更多相关文章

题目 题目     分析 没有估价函数的IDA......     代码 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int q,dx[10]={2,2,-2,-2,1,-1,1,-1},dy[10]={1,-1,1,-1,2,2,-2,-2},ans=1<<15; bool vis[11][11]; int x1,y1,x2,y2; bool…
题目 题目     分析 bfs可以搞,但是我还是喜欢dfs,要记忆化不然会T     代码 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int INF=1<<25; int k,n,m,map[25][25],dx[10]={1,-1,0,0},dy[10]={0,0,1,-1},ans; int vis[25][25][25];…
题目 题目     分析 典型搜索,考虑剪枝. 统计一下联通分量. 1.本位置能够达到所有的点的数量加上本已有的点,还没有之前的结果长,直接返回. 2.当本位置能够达到所有的点的数量加上本已有的点与之前的结果一样长,就把联通分量里的点从大到小排序.如果这样都比Ans小,那么直接返回. 前两种是大多人用的,这两个剪枝有了,AC不是问题. 3.如果本图没有障碍物,那么意味着所有点联通,那么结果必定是从整张图的最大值出发的,非最大值,就不用考虑了. 这个是我自己想的,大约能剪 40-80 ms. 个人…
http://www.lydsy.com/JudgeOnline/problem.php?id=1024 果然现在弱到连搜索都不会了么..... 一直想二分...但是无论如何也推不出怎么划分... QAQ 然后暴力搜索每一次割的时候左边右边各有几块或者上边下边各有几块就行了QAQ #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostr…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=27&page=show_problem&problem=2549 设w[i,j]为i-j能分割成的最少回文串 f[i]为前i个字符能够分成的最少回文串 w[i,j]=1 当w[i+1,j-1]==1 && s[i]==s[j] 或 i==j-1 && s[i]==s[j] w[i,j]=…
题目 题目     分析 IDA*大法好,抄了lrj代码.     代码 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxans=14; int n,a[maxans+1]; bool dfs(int d,int maxd) { if(a[d] == n) return true; if(d == maxd) return false;…
题意:二维平面上有两个框,问平面被分成了几个部分 x,y<=1e9 思路:分类讨论可以 但数据范围实在太小了,离散化以后随便dfs一下 #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int,int> PII; typedef pair<ll,…
题目 题目     分析 算是个模拟吧     代码 #include <bits/stdc++.h> using namespace std; map<int,int> a[130]; char s[85]; int n[130]; int PosIs() { int len=strlen(s); for(int i=0;i<len;i++) if(s[i]=='=') return i; return -1; } int get_num(int k) { int res=…
题目 题目     分析 没什么好说的,字符串拼接一下再放进map.其实可以直接开俩数组排序后对比一下,但是我还是想熟悉熟悉map用法. 呃400ms,有点慢.     代码 #include <bits/stdc++.h> using namespace std; int read(string a) { int ans=0,i=0; while(i<a.length()){ans=(ans<<3)+(ans<<1)+a[i]-'0';i++;} return…
P3379 [模板]最近公共祖先(LCA) 题目描述 如题,给定一棵有根多叉树,请求出指定两个点直接最近的公共祖先. 输入输出格式 输入格式: 第一行包含三个正整数N.M.S,分别表示树的结点个数.询问的个数和树根结点的序号. 接下来N-1行每行包含两个正整数x.y,表示x结点和y结点之间有一条直接连接的边(数据保证可以构成树). 接下来M行每行包含两个正整数a.b,表示询问a结点和b结点的最近公共祖先. 输出格式: 输出包含M行,每行包含一个正整数,依次为每一个询问的结果. 输入输出样例 输入…