1#include <iostream>2#include <cstdlib>3#include <cstring>4#include <queue>5#include <cstdio>6#include <algorithm>7#include <map>8 //#include <time.h>9 //#include <ext/pb_ds/assoc_container.hpp>Ten //#include <ext/pb_ds/tree_policy.hpp> One #defineLL Long Long A - using namespacestd; - //using namespace __gnu_pbds; the - intdp[1<< -][ -]; - - intN; + - structnodes + { A intx, y; at int operator- (ConstNodes &b)Const - { - returnMax (ABS (x-b.x), ABS (Y-b.y)); - } -}point[ -]; - in intDfsintStatu,intcur) - { to if(Dp[statu][cur]! =-1) + returnDp[statu][cur]; - if(Statu = = (1<< (n+1) )-1&& cur = =0) the returnDp[statu][cur] =0; *Dp[statu][cur] =0x3f3f3f; $ Panax Notoginseng for(inti =0; I <= N; i++) - { the if(((Statu >> i) &1) ==1)Continue; +Dp[statu][cur] = min (Dp[statu][cur], DFS (statu| (1<<i), I) + (point[cur]-point[i])); A } the + returnDp[statu][cur]; - } $ $ voidSolve () - { -memset (dp,-1,sizeof(DP)); the intRow,col; -scanf"%d%d",&row,&col);Wuyi Charss[ -]; then =0; - for(inti =1; I <= row; i++) Wu { -scanf"%s", ss+1); About for(intj =1; J <= Col; J + +) $ if(Ss[j] = ='x') - { -point[0].x =i; -point[0].Y =J; A } + Else if(Ss[j] = ='g') the { -point[++n].x =i; $POINT[N].Y =J; the } the } the intAns = DFS (0,0); theprintf"%d\n", ans); - } in the the intMainvoid) About { the intt,cnt =0; thescanf"%d",&t); the while(t--) + { -printf"Case %d:",++CNT); the solve ();Bayi } the return 0; the}
Light OJ 1057-shape pressure DP TSP