2019百度之星 - 复赛 HDU-6726 Transformation 搜索剪枝

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6726

题解:我们倒着往前找,对于(a,2b-a)->(x,y)那么x+y为偶数,(x, y) 往前的话就是(x, (x+y)/2),所以x和y是渐渐靠拢的,所以max(a,b)min(x,y),这样剪枝就能过了

#include
#include
#include
using namespace std;
typedef long long ll;
string ans;
ll a,b,c,d;
void dfs(ll x,ll y,string s){
    if(x==a&&y==b){
        reverse(s.begin(),s.end());
        ans=min(ans,s);
        return ;
    }
    if(((x+y)&1)==1||max(a,b)>max(x,y)||min(a,b)

 

你可能感兴趣的:(dfs,暴力(枚举技巧))