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"