hdu 5653 Bomber Man wants to bomb an Array

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5653

题意:已知炸弹可以炸掉左边L个位置,右边R个位置,那么炸点炸掉的总数是L+R+1。给定每个炸弹的位置,求所有炸弹炸掉的格数总乘积

输出floor(1e6*log2(总乘积))那么到计算时就变成先取对数相加,最后乘以1e6下取整

思路:dp[r]=dp[l-1]*log2(r-l+1)当前区间的最大值等于上一个区间的最大值加上当前的值,解释见代码

 1 #include<cstdio>  
 2 #include<iostream>  
 3 #include<algorithm>
 4 #include<math.h> 
 5 #include<string.h>  
 6 #include<vector> 
 7 #include<queue>
 8 #include<map>
 9 #include<iterator>
10 #include<vector>
11 #include<set>
12 #define INF 9999999
13 typedef long long ll;
14 const int Max=(1<<16)+10;
15 using namespace std;
16 
17 double dp[10005];
18 int num,n,m,b[10005];
19 
20  
21  int main()
22  {
23      scanf("%d",&num);
24      while(num--)
25     {
26         scanf("%d %d",&n,&m);
27         for(int i=1;i<=m;i++)
28         {
29             scanf("%d",&b[i]);
30             b[i]++;
31         }
32             
33          sort(b+1,b+m+1);
34          
35          b[m+1]=n+1; 
36          memset(dp,0,sizeof(dp));
37          
38          for(int i=1;i<=m;i++)
39          {
40              for(int j=b[i-1]+1;j<=b[i];j++)
41              {
42                  for(int k=b[i];k<=b[i+1]-1;k++)
43                      dp[k]=max(dp[k],dp[j-1]+log2(k-j+1.0));//枚举区间求最大值,j表示当前区间的起点,k表示当前区间的终点,j-1表示上一个区间 
44             }
45         }
46         ll ans=floor(1e6*dp[n]);
47         printf("%lld
",ans);
48     } 
49     return 0;
50   } 
51 
52  
原文地址:https://www.cnblogs.com/pter/p/5532677.html