这道题用构造法, 就是自己依据题目想出一种可以得到解的方法, 没有什么规律可言, 只能根据题目本身来思考. 这道题的构造法比较复杂, 不知道刘汝佳是怎么想出来的, 我想的话肯定想不到. 具体思路紫书上讲得非常清楚了, 就不讲了.代码有详细注释 #include<cstdio> #include<vector> #define REP(i, a, b) for(int i = (a); i < (b); i++) using namespace std; const int M…
思路是按紫书上说的来. 参考了:https://blog.csdn.net/qwsin/article/details/51834161 的代码: #include <cstdio> #include <iostream> #include <cmath> using namespace std; typedef unsigned long long ll; +; ll a, b; int n,M; int f[MAXN*MAXN]; int pow_mod(ll p…
传送门: 1. UVA - 10562 2. Vjudge [看图写树] 将题目中给出的树改写为 括号表示法 即 (ROOT (SON1(...) (SON2(...)...(SONn(...))的表示方法,空树括号留空,例如: A | -------- B C D | | ----- - E F G # e | ---- f g # 上图有两棵树,'#'指该棵树如入完毕,将要表示为: (A(B()C(E()F())D(G()))) (e(f()g())) 分析:递归求解的经典题,类似于…
八数码问题 紫书上的简单搜索 渣渣好久才弄懂 #include<cstdio> #include<cstring> using namespace std; const int M = 1000003; int x[4] = { -1, 1, 0, 0}, y[4] = {0, 0, -1, 1}; int dis[M], h[M], s[M][9], e[9]; int aton(int a[]) { int t = 0; for(int i = 0; i < 9; +…
题目链接: https://cn.vjudge.net/problem/UVA-10562 Professor Homer has been reported missing. We suspect that his recent research works might have had something to with this. But we really don't know much about what he was working on! The detectives tried…