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<< -]; - - intattack[ -][ -],health[ -]; + - intN; + A intCheckintJinti) at { - intA =1; -A =Max (a,attack[j][i]); - return(health[i]/a) + (health[i]%a?)1:0); - } - in intDfsintstatu) - { to if(Dp[statu]! =-1) + returnDp[statu]; -Dp[statu] =0x3f3f3f3f; the if(Statu = =0) * returnDp[statu] =0; $ for(inti =1; I <= N; i++)Panax Notoginseng { - if((Statu>> (i1)) &1) ==0 ) the Continue; +Dp[statu] = min (Dp[statu],dfs (statu^ (1<< (I-1))) +health[i]/1); A for(intj =1; J <= N; J + +) the { + if(i = = j)Continue; - $ if((Statu>> (J-1)) &1) ==0) $ { -Dp[statu] = min (Dp[statu],dfs (statu^ (1<< (I-1)) )) +Check (j,i)); - } the } - Wuyi } the - returnDp[statu]; Wu } - About voidSolve () $ { -memset (dp,-1,sizeof(DP)); - -scanf"%d",&n); A for(inti =1; I <= N; i++) +scanf"%d",&health[i]); the for(inti =1; I <= N; i++) - for(intj =1; J <= N; J + +) $scanf"%1d",&attack[i][j]); the the intAns = DFS ((1<<n)-1); the 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 1037-shape pressure DP