HZAU1098: Yifan and War3(区间dp)
来源:互联网 发布:淘宝卖家如何删除评价 编辑:程序博客网 时间:2024/05/22 08:33
1098: Yifan and War3
Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 622 Solved: 20
[Submit][Status][Web Board]
Description
As we all know, There is a hero called Priestess of the Moon(POM), which has apassive ability named 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
310 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
看了其他人的思路整理出来。相似题目:POJ1651:Multiplication Puzzle
# include <stdio.h># include <string.h>int min(int a, int b){ return a<b?a:b;}int main(){ int dp[202][202] = {0}, a[202], i, n, k, len, imin, imin1, imin2; while(scanf("%d",&n) != EOF) { memset(a, 0, sizeof(a)); memset(dp, 0, sizeof(dp)); for(i=1; i<=n; ++i) scanf("%d",&a[i]); a[0] = a[n+1] = 0; for(i=1; i<=n; ++i) dp[i][i] = a[i-1]+a[i]+a[i+1]; for(len=1; len<=n; ++len) { for(i=1; i+len<=n; ++i) { //相当于枚举最后消去的点 imin1 = dp[i+1][i+len]+a[i-1]+a[i+len+1]+a[i]; //为第一个点的情况 imin2 = dp[i][i+len-1] + a[i+len]+a[i-1]+a[i+len+1];//为最后一个点的情况 imin = min(imin1, imin2); for(k=i+1; k<i+len; ++k)//为点在中间的情况 imin = min(imin, dp[i][k-1]+dp[k+1][i+len]+a[k]+a[i-1]+a[i+len+1]); dp[i][i+len] = imin; } } printf("%d\n",dp[1][n]); } return 0;}
0 0
- HZAU1098: Yifan and War3(区间dp)
- 华中农大HZAUOJ 1098 Yifan and War3 区间dp
- HDOJ 5115 Dire Wolf /HZAUOJ 1098 Yifan and War3 (裸区间dp)
- HDU5900-QSC and Master(区间dp)
- 1008 QSC and Master (区间dp)
- hdu5900QSC and Master(区间dp)
- hdu5900 QSC and Master(区间dp)
- hdu5900 QSC and Master(区间DP)
- HDU5900 QSC and Master(区间dp)
- HDU5900 QSC and Master(区间dp)
- Pangu and Stones(区间dp)
- HDU5900QSC and Master (区间DP)
- QSC and Master 区间dp
- pangu and stones(区间dp)
- URAL 1635. Mnemonics and Palindromes(简单区间dp)
- CF 467C - George and Job (简单区间DP)
- HDU 5900 QSC and Master(区间DP)
- HDU-5900-QSC and Master(区间DP)
- php初步入门(四)
- greenlet 模块源码
- 10个方法让程序员更加优秀
- jQuery属性选择器
- Servlet学习二
- HZAU1098: Yifan and War3(区间dp)
- 开通
- android中xmlns:tools属性详解
- Oracle中start with…connect by prior子句用法
- fonts/fontawesome-webfont.woff2 404
- 职工信息结构体
- Windows 下的离线API阅读器(MAC OS 的 DASH)
- 2.2请求URI定位资源
- 八款实用软件