华中农大HZAUOJ 1098 Yifan and War3 区间dp
2016-12-23 21:44
323 查看
1098: Yifan and War3
Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 637 Solved: 23
[Submit][Status][Web
Board]
Description
As we all know, There is a hero called Priestess of the Moon(POM), which has a passive abilitynamed Trueshot Aura . It can add other units some ranged attacks . Fanfan love the Human very
much, and he will battle with a Night Elf everyday , because he thinks the Night Elf can’t attack his tower easily .But today , he met a Night Elf player , who use POM as his first hero, and had lots of Archers . Fanfan use theMountain
King to kill the Archers ,and don’t know how many health he need to kill all the Archers .Could you help him ?
To make the problem simple , we assume that all the Archers stand in a line , they have different attacks , if Fanfan kills the ith Archer , the (i+1)th and the (i-1)th Archer will help to attack Fanan by their own
attacks . There are N Archers , and Fanfan wants to know the least damage he will get to kill all the Archers .
Input
First line contains an integer N (0<N<200), means there are N Archers .Then the next line contains N integers ai(0<ai<100000) means that the ith Archers have ai attacks .
Output
An integer means the least damage Fanfan will get.
Sample Input
3 10 100 10
Sample Output
150
HINT
Yifan first kill the second Archer , get 100+10+10 demages , and then kill the first one ,get 10+10 demages and finally kill the third one and get 10 demages so, he get 150 demage
由于是原题,无耻地抢下了一血成功把榜带歪。。。。。
详细见hdu5115的题解
代码:
#include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include <cstdio> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 300; int basic[maxn],extra[maxn]; int dp[maxn][maxn]; int main(){ int t,n,i,j,k,len; while(~scanf("%d",&n)){ for(i=1;i<=n;i++){ scanf("%d",&basic[i]); extra[i] = basic[i]; } basic[0] = 0,basic[n+1] = 0; extra[0] = 0,extra[n+1] = 0; memset(dp, 0, sizeof(dp)); for(i=1;i<=n;i++){ for(j=i;j<=n;j++){ dp[i][j]=INF; } } for(len=1;len<=n;len++){ for(i=1;i<=n-len+1;i++){ int j = i+len-1; for(k=i;k<=j;k++){ dp[i][j] = min(dp[i][j],dp[i][k-1]+dp[k+1][j]+basic[k]+extra[i-1]+extra[j+1]); } } } printf("%d\n",dp[1] ); } return 0; }
相关文章推荐
- HDOJ 5115 Dire Wolf /HZAUOJ 1098 Yifan and War3 (裸区间dp)
- 南阳理工OJ 石子归并(经典区间DP)
- light oj 1422 - Halloween Costumes (区间dp)
- 华中农大HZAUOJ 1097 1099 BFS、数据类型小心
- HZAU1098: Yifan and War3(区间dp)
- [BZOJ4574][UOJ#196][Zjoi2016][区间DP][概率]线段树
- 区间dp||记忆化搜索 Game of Sum UVA - 10891 or Light OJ 1031---Easy Game(区间DP)
- hzauoj Problem J: Arithmetic Sequence (dp)
- [Swust OJ 360]--加分二叉树(区间dp)
- CSUOJ - 1592石子归并(区间DP)
- poj2955Brackets(区间DP)
- Brackets(POJ - 2955)区间dp
- hihoCode #1338 : A Game (区间dp)
- nyoj 1030 Yougth's Game[Ⅲ](区间dp 博弈组合题)
- 【日常学习】【区间DP+高精】codevs1166 矩阵取数游戏题解
- 洛谷 P3102 [USACO14FEB]秘密代码Secret Code 【区间dp】
- poj 3186 Treats for the Cows(区间dp)
- HDU 5900 QSC and Master 区间DP
- 石子合并问题(一) (基础的区间dp)
- UVA 1626 - Brackets sequence 区间DP