HDU5115 Dire Wolf

Source: Internet
Author: User

Time Limit: 5000MS Memory Limit: 512000KB 64bit IO Format: %i64d &%i64u

Description

Dire Wolves, also known as Dark Wolves, is extraordinarily large and powerful wolves. Many, if not all, Dire wolves appear to originate from Draenor.
Dire wolves look like normal wolves, but these creatures is of nearly twice the size. These powerful beasts, 8-9 feet long and weighing 600-800 pounds, is the most well-known ORC mounts. As tall as a man, these great wolves has a long tusked jaws that look like they could snap an iron bar. They has burning red eyes. Dire wolves is mottled gray or black in color. Dire wolves thrive in the northern regions of Kalimdor and in Mulgore.
Dire Wolves is efficient pack hunters that kill anything they catch. They prefer to attack in packs, surrounding and flanking a foe when they can.
―wowpedia, Your Wiki Guide to the world of WARCRA??

Matt, an adventurer from the Eastern kingdoms, meets a pack of dire wolves. There is N wolves standing in a row (numbered with 1 to N from left to right). Matt has the defeat all of them to survive.

Once Matt defeats a dire wolf, he'll take some damage which are equal to the wolf's current attack. As gregarious beasts, each dire wolf I can increase it adjacent wolves ' attack by B I. Thus, each dire wolf I's current attack consists of the II parts, its basic attack AI and the extra attack provided by the CU Rrent adjacent wolves. The increase of attack is temporary. Once A wolf is defeated, its adjacent wolves would no longer get extra attack from it. However, these, wolves (if exist) would become adjacent to each and now.

For example, suppose there is 3 dire wolves standing in a row, whose basic attacks Ai is (3, 5, 7), respectively. The extra attacks B I they can provide are (8, 2, 0). Thus, the current attacks of them is (5, 13, 9). If Matt defeats the second Wolf first, he'll get points of damage and the Alive Wolves ' current attacks become (3, 15 ).

As an alert and resourceful adventurer, Matt can decide the order of the dire wolves he defeats. Therefore, he wants to know the least damage he had to take to defeat all the wolves.

Input

The first line contains only one integer T, which indicates the number of test cases. For each test case, the first line contains only one integer N (2≤n≤200).

The second line contains N integers a I (0≤a i≤100000), denoting the basic attack of each dire wolf.

The third line contains N integers b I (0≤b i≤50000), denoting the extra attack each dire wolf can provide.

Output

For each test case, output a single line "Case #x: Y", where x was the case number (starting from 1), and Y is the least damage Matt needs to take.

Sample Input

233 5 78 2 0101 3 5 7 9 2 4 6 8 109 4 1 2 1 2 1 4 5 1

Sample Output

Case #1:17Case #2:74         

Hint

In the-rst sample, Matt defeats the dire wolves from left to right. He takes 5 + 5 + 7 = Points of damage which is the least damage he have to take.

Source

2014ACM/ICPC Asia Beijing Station-Replay (thanks to the North Division and handing in) the fan range DP. Because each attack has to consider the damage from both sides of the target, the interval length of 2 is difficult to handle. As long as the DP array is specially processed at initialization time. See the code specifically:
1 /*by Silvern*/2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cstdio>6#include <cmath>7 using namespacestd;8 Const intmxn= -;9 intRead () {Ten     intx=0, f=1;CharCh=GetChar (); One      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} A      while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} -     returnx*F; - } the intT; - intN; - intA[MXN],B[MXN]; - intF[MXN][MXN]; + intMain () { -t=read (); +     inti,j; A     intcas=0; at      while(t--){ - //memset (f,0x3f,sizeof f); -Memset (F,0,sizeoff); -n=read (); -          for(i=1; i<=n;i++) {a[i]=read ();} -          for(i=1; i<=n;i++) {b[i]=read ();} ina[n+1]=b[n+1]=0; -          for(i=1; i<=n;i++) to              for(j=i;j<=n;j++) +                 if(I==J) f[i][i]=a[i]+b[i-1]+b[i+1]; -                 Elsef[i][j]=0x3f3f3f3f; the          for(intst=1; st<=n;st++) *            for(i=1; i<=n-st;i++){ $j=i+St;Panax Notoginseng                for(intk=i;k<=j;k++){ -F[i][j]=min (f[i][j],f[i][k-1]+f[k+1][j]+a[k]+b[i-1]+b[j+1]); the               } + //printf ("%d%d%d\n", i,j,f[i][j]); A           } the          +printf"Case #%d:%d\n", ++cas,f[1][n]); -     } $     return 0; $}

HDU5115 Dire Wolf

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.