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

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/p/2677966.html