Light OJ 1037-shape pressure DP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.