HDOJ 4848 Wow! Such Conquering!

Source: Internet
Author: User

HDOJ 4848 Wow! Such Conquering!


Dfs + subtraction ....

Wow! Such Conquering! Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 651 Accepted Submission (s): 195


Problem DescriptionThere are n Doge Planets in the Doge Space. the conqueror of Doge Space is Super Doge, who is going to inspect his Doge Army on all Doge Planets. the inspection starts from Doge Planet 1 where DOS (Doge Olympus IC Statue) was built. it takes Super Doge exactly Txy time to travel from Doge Planet x to Doge Planet y.
With the ambition of conquering other spaces, he wowould like to visit all Doge Planets as soon as possible. more specifically, he wowould like to visit the Doge Planet x at the time no later than Deadlinex. he also wants the sum of all arrival time of each Doge Planet to be as small as possible. you can assume it takes so little time to inspect his Doge Army that we can ignore it.
InputThere are multiple test cases. Please process till EOF.
Each test case contains several lines. the first line of each test case contains one integer: n, as mentioned above, the number of Doge Planets. then follow n lines, each contains n integers, where the y-th integer in the x-th line is Txy. then follows a single line containing n-1 integers: Deadline2 to Deadlinen.
All numbers are guaranteed to be non-negative integers smaller than or equal to one million. n is guaranteed to be no less than 3 and no more than 30.
OutputIf some Deadlines can not be fulfilled, please output "-1" (which means the Super Doge will say "WOW! So Slow! Such delay! Much Anger! ... ", But you do not need to output it), else output the minimum sum of all arrival time to each Doge Planet.

Sample Input
40 3 8 64 0 7 47 5 0 26 9 3 030 8 3040 2 3 32 0 3 32 3 0 32 3 3 02 3 3

Sample Output
36-1HintExplanation:In case #1: The Super Doge travels to Doge Planet 2 at the time of 8 and to Doge Planet 3 at the time of 12,then to Doge Planet 4 at the time of 16.The minimum sum of all arrival time is 36. 

Source2014 Xi'an national invitational Competition

#include 
 
  #include 
  
   #include 
   
    #include #include 
    
     using namespace std;int n,ans;int g[40][40],deadline[40];bool vis[40];void dfs(int u,int alltime,int time,int num){    if(num==0)    {        ans=min(ans,alltime);        return ;    }    for(int i=1;i<=n;i++)    {        if(vis[i]) continue;        int T=time+g[u][i];        bool flag=true;        if(alltime+T*(num-1)>ans) continue;        for(int j=1;j<=n;j++)        {            if(vis[j]) continue;            if(deadline[j]
     
      



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.