HDU 5115 Dire Wolf "Interval DP"

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5115

Test instructions
There are n wolves, each wolf has two kinds of properties, a kind of attack value, we did not kill a wolf, then we received the damage value of the wolf's attack value with the two wolves next to the added value of the and, to kill all the wolves to the minimum damage value.

Code:

#include <stdio.h>#include <ctime>#include <math.h>#include <limits.h>#include <complex>#include <string>#include <functional>#include <iterator>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <set>#include <map>#include <list>#include <bitset>#include <sstream>#include <iomanip>#include <fstream>#include <iostream>#include <ctime>#include <cmath>#include <cstring>#include <cstdio>#include <time.h>#include <ctype.h>#include <string.h>#include <assert.h>using namespace STD;intNinta[ -],b[ -],dp[ -][ -];intMain () {intT, cases =1;scanf("%d", &t); while(t--) {scanf("%d", &n); for(inti =0; I <= N; i++) for(intj =0; J <= N; J + +) Dp[i][j] =100000000;memsetA0,sizeof(a));memset(b,0,sizeof(b)); for(inti =1; I <= N; i++)scanf("%d", &a[i]); for(inti =1; I <= N; i++)scanf("%d", &b[i]); for(inti =1; I <= N; i++) Dp[i][i] = A[i] + b[i-1] + b[i +1]; for(intL =1; L <= N; l++) { for(inti =1; i + L <= N; i++) {intj = i + L; Dp[i][j] = min (dp[i+1][J] + b[i-1] + b[j+1] + a[i], dp[i][j-1] + A[j] + b[j +1] + b[i-1]); for(intK = i+1; K <= J; k++) {Dp[i][j] = min (dp[i][j], dp[i][k-1] + dp[k +1][J] + a[k] + b[i-1] + b[j +1]); }            }        }printf("Case #%d:%d\n", cases++, dp[1][n]); }return 0;}

Copyright NOTICE: Reprint please indicate the source.

Hdu 5115 Dire Wolf "Interval 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.