记录编号 81860 评测结果 AAAAAAAAAA
题目名称 [NOIP 2013]积木大赛 最终得分 100
用户昵称 Gravatarcstdio 是否通过 通过
代码语言 C++ 运行时间 0.023 s
提交时间 2013-11-18 22:12:19 内存使用 0.70 MiB
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<cstring>
  5. #include<iomanip>
  6. #include<algorithm>
  7. using namespace std;
  8. const int SIZEN=100001;
  9. int h[SIZEN]={0};
  10. int n;
  11. class COUPLE{
  12. public:
  13. int lh,rh;
  14. int opn;//操作数
  15. };
  16. COUPLE DP(int left,int right){
  17. if(left==right){
  18. return (COUPLE){h[left],h[left],h[left]};
  19. }
  20. int mid=(left+right)>>1;
  21. COUPLE lf,rf;
  22. lf=DP(left,mid);
  23. rf=DP(mid+1,right);
  24. COUPLE now;
  25. now.lh=lf.lh,now.rh=rf.rh;
  26. now.opn=lf.opn+rf.opn-min(lf.rh,rf.lh);
  27. return now;
  28. }
  29. void read(void){
  30. scanf("%d",&n);
  31. int i;
  32. for(i=1;i<=n;i++) scanf("%d",&h[i]);
  33. }
  34. int main(){
  35. freopen("BlockNOIP2013.in","r",stdin);
  36. freopen("BlockNOIP2013.out","w",stdout);
  37. read();
  38. COUPLE ans=DP(1,n);
  39. printf("%d\n",ans.opn);
  40. return 0;
  41. }