http://acm.hdu.edu.cn/showproblem.php?pid=4283

题意:

The TV shows such as You Are the One has been very popular. In order to meet the need of boys who are still single, TJUT hold the show itself. The show is hold in the Small hall, so it attract a lot of boys and girls. Now there are n boys enrolling in. At the beginning, the n boys stand in a row and go to the stage one by one. However, the director suddenly knows that very boy has a value of diaosi D, if the boy is k-th one go to the stage, the unhappiness of him will be (k-1)*D, because he has to wait for (k-1) people. Luckily, there is a dark room in the Small hall, so the director can put the boy into the dark room temporarily and let the boys behind his go to stage before him. For the dark room is very narrow, the boy who first get into dark room has to leave last. The director wants to change the order of boys by the dark room, so the summary of unhappiness will be least. Can you help him?

题解:

dp

dp[s][e][k]表示 将从 s 到e  这个 段上台的话(前面 已经有 k个上过台的 最小值),

 1 #include<cstdio>
 2  #include<cstring>
 3  #include<cmath>
 4  #include<iostream>
 5  #include<algorithm>
 6  #include<set>
 7  #include<map>
 8  #include<queue>
 9  #include<vector>
10  #include<string>
11  #define Min(a,b) a<b?a:b
12  #define Max(a,b) a>b?a:b
13  #define CL(a,num) memset(a,num,sizeof(a));
14  #define eps  1e-12
15  #define inf 100000000
16  #define mx  10
17 
18  const double pi  = acos(-1.0);
19  const int  maxn = 105;
20  typedef   __int64  ll;
21  using namespace std;
22  int dp[maxn][maxn][maxn] ,a[maxn];
23  int dfs(int s,int e,int k)
24  {
25      if(s == e)  return a[s]*k ;
26      if(s > e) return  0 ;
27      if(dp[s][e][k]!=inf) return dp[s][e][k] ;
28      int mi = dfs(s + 1,e,k + 1) + a[s]*k ;
29      for(int  i = s+1;i <= e;i++)
30      {
31          int  l = dfs(s + 1,i,k);
32          int  r = dfs(i + 1 ,e,k + i + 1 - s);
33          int tp = a[s]*(k + i - s);
34          tp = l + r + tp;
35          if(mi > tp) mi = tp ;
36 
37      }
38      dp[s][e][k] = mi;
39      return mi ;
40  }
41  int main()
42  {
43      int t,i,j,k,n;
44      int cas = 0;
45      scanf("%d",&t);
46      while(t--)
47      {
48          scanf("%d",&n);
49          for(i =  1; i<=n;i++)
50          {
51              scanf("%d",&a[i]);
52          }
53          for(i =0 ; i <=n;i++)
54          {
55              for(j = 0;j<=n;j++)
56              {
57                  for(k = 0 ; k<=n;k++)
58                  {
59                      dp[i][j][k] = inf ;
60                  }
61              }
62          }
63          for(i = 1;i<=n;i++)
64          {
65              for(k = 0; k <= n;k++)
66              {
67                  dp[i][i][k] = a[i]*k ;
68              }
69          }
70          dfs(1,n,0);
71          printf("Case #%d: %d\n",++cas,dp[1][n][0]);
72       }
73  }

转载于:https://www.cnblogs.com/acSzz/archive/2012/09/09/2677966.html

hdu 4283 You Are the One ( dp 2012 ACM/ICPC Asia Regional Tianjin Online )相关推荐

  1. HDU 5476 Explore Track of Point 几何题 —— 2015 ACM/ICPC Asia Regional Shanghai Online

    题目见HDU 5476 给出等腰三角形ABC,AB=AC,M为BC中点.P点为三角形内使min{∠MPB+∠APC,∠MPC+∠APB} 最大的点.求P点轨迹. 则容易找到中线AM上的P点都满足使得∠ ...

  2. hdu 5023 poj 2777(线段染色)2014 ACM/ICPC Asia Regional 广州 Online

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5023 http://poj.org/problem?id=2777 题意:给出一个长度为N的线段,分 ...

  3. HDU 4069 Squiggly Sudoku(DLX)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)...

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4069 Problem Description Today we play a squiggly sud ...

  4. hdu 5444 Elven Postman(根据先序遍历和中序遍历求后序遍历)2015 ACM/ICPC Asia Regional Changchun Online...

    很坑的一道题,读了半天才读懂题,手忙脚乱的写完(套上模板+修改模板),然后RE到死-- 题意: 题面上告诉了我们这是一棵二叉树,然后告诉了我们它的先序遍历,然后,没了--没了! 反复读题,终于在偶然间 ...

  5. HDU - 5493 Queue 2015 ACM/ICPC Asia Regional Hefei Online(线段树)

    按身高排序,每个人前面最高的人数有上限,如果超出上限说明impossible, 每次考虑最小的人,把他放在在当前的从左往右第k+1个空位 因为要求字典序最小,所以每次k和(上限-k)取min值. 没有 ...

  6. HDU 6194 String String String (后缀数组+线段树, 2017 ACM/ICPC Asia Regional Shenyang Online)

    Problem 求字符串 S 中严格出现 k 次的子串个数 k≥1k\ge 1 |S|≤105|S|\le 10^5 ∑|S|≤2×106\sum |S| \le 2\times 10^6 Idea ...

  7. Hdu 5873 2016 ACM/ICPC Asia Regional Dalian Online 1006(兰道定理)

    题解: 如果没有平手选项, 赢得加一分的话, 可以用Landau's Theorem(兰道定理)判定. 稍微修改一下这个定理就能做了. 假设S1,S2--,Sn是他们的得分序列,从小到大排个序.那么这 ...

  8. HDU 5468 Puzzled Elena(2015 ACM/ICPC Asia Regional Shanghai Online)

    题目大意 这道题要求出每个节点与其子树节点中有多少个节点互质,题目是这样,但是如果你认为真的是这样那就错了,因为有可能根节点是1,那么1与本身也是互质的!!其实我真的搞不懂,说好了与子树互质为什么就把 ...

  9. HDU - 6208 The Dominator of Strings n次KMP 2017 ACM/ICPC Asia Regional Qingdao Online

    找到最长串 然后进行n次KMP #include <iostream> #include <cstdio> #include <cstdlib> #include ...

最新文章

  1. 安装Exchange2013,FMS服务无法达到启动状态
  2. 成都华育php笔试题,一套PHP的笔试题
  3. 如何在10亿数中找出前1000大的数
  4. 利用虚拟硬盘(把内存当作硬盘)来提高数据库的效率(目前只针对SQL Server 2000)可以提高很多...
  5. Linux下启动mongodb
  6. 酒桌上的规矩,社会的潜规则
  7. IIS之Web服务器
  8. java tutorial mobi_Java 初学者List集合教程
  9. 云原生时代,分布式系统设计必备知识图谱(内含22个知识点)
  10. 浪潮信息能制造超级计算机吗,浪潮信息为中国航天探索事业出力 高性能计算技术领衔...
  11. 三阶魔方还原步骤图_3阶魔方教程 1~7步骤,三阶魔方顶层还原图解
  12. 机器学习实战K-近邻算法
  13. 【盘点】最受欢迎十大中国风歌曲
  14. 安微六安二中2021高考成绩查询,喜报!六安一中、六安二中、毛坦厂中学......高考“成绩单”出炉...
  15. flex子项常见属性 跟携程网首页案例制作。
  16. 面向越野地形自动驾驶的语义地形分类
  17. 北京邮电大学计算机学院马华东,马华东(博导)
  18. python评分卡4_logistics原理与解法_sklearn英译汉
  19. qq 4 android,Android QQ HD v5.5.4 正式版发布
  20. 【红宝书笔记精简版】第十二章 BOM

热门文章

  1. Step by Step-构建自己的ORM系列-索引
  2. 《Windows Phone 7 用户界面设计和交互指南 v2.0》
  3. 数据绑定--Repeater, DataList, or GridView?
  4. 【操作系统】死锁-思维导图
  5. linux定时任务生效_Linux 添加定时任务
  6. maven怎么引入自定义(本地/第三方)jar图文教程
  7. Selenium2+python自动化64-100(大结局)[已出书]
  8. 40岁,将站到哪里(转)
  9. Freemodbus 1.5
  10. postfix邮件队列管理