zoukankan      html  css  js  c++  java
  • HDU 5653 Bomber Man wants to bomb an Array. dp

    Bomber Man wants to bomb an Array.

    题目连接:

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

    Description

    Given an array and some positions where to plant the bombs, You have to print the Total Maximum Impact.

    Each Bomb has some left destruction capability L and some right destruction capability R which means if a bomb is dropped at ith location it will destroy L blocks on the left and R blocks on the right.
    Number of Blocks destroyed by a bomb is L+R+1
    Total Impact is calculated as product of number of blocks destroyed by each bomb.
    If ith bomb destroys Xi blocks then TotalImpact=X1∗X2∗....Xm

    Given the bombing locations in the array, print the Maximum Total Impact such that every block of the array is destoryed exactly once(i.e it is effected by only one bomb).

    Rules of Bombing

    1. Bomber Man wants to plant a bomb at every bombing location.
    2. Bomber Man wants to destroy each block with only once.
    3. Bomber Man wants to destroy every block.

    Input

    There are multi test cases denote by a integer T(T≤20) in the first line.

    First line two Integers N and M which are the number of locations and number of bombing locations respectivly.
    Second line contains M distinct integers specifying the Bombing Locations.

    1 <= N <= 2000

    1 <= M <= N

    Output

    as Maximum Total Impact can be very large print the floor(1000000 * log2(Maximum Total Impact)).

    Sample Input

    2
    10 2
    0 9
    10 3
    0 4 8

    Sample Output

    4643856
    5169925

    Hint

    题意

    一个长为n的地方,有m个炸弹。

    每个炸弹可以炸掉l+r+1的位置,表示这个炸弹炸掉左边l个,右边r个,自己所在的一个

    然后他们炸完之后,的贡献就是a[1]*a[2]*....*a[n]

    a[i]表示第i个炸掉了多少个

    题解:

    数据范围只有2000,所以直接暴力dp去枚举就好了

    dp[i][j]表示考虑到第i个炸弹,炸到j的最大值

    然后直接自信n^3瞎转移就好了

    代码

    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<stdio.h>
    #include<cstring>
    using namespace std;
    const int maxn = 2005;
    int n,m,a[maxn] ;
    double dp[maxn][maxn];
    
    int main()
    {
        int t;scanf("%d",&t);
        while(t--)
        {
            scanf("%d%d",&n,&m);
            memset(a,0,sizeof(a));
            memset(dp,0,sizeof(dp));
            for(int i=1;i<=m;i++)
                scanf("%d",&a[i]),a[i]++;
            sort(a+1,a+1+m);
            a[++m]=n+2;
            for(int i=1;i<=a[1];i++)
                dp[1][i]=1;
            for(int i = 2 ; i <= m ; ++ i){
                for(int j = a[i-1]+1;j<=a[i];++j)
                    for(int k = a[i-2]+1 ; k <= a[i-1] ; ++ k )
                        dp[i][j]=max(dp[i][j],dp[i-1][k]*(j-k));
            }
            printf("%.0f
    ",floor(1000000.0 * log2(dp[m][n+1])));
        }
        return 0;
    }
  • 相关阅读:
    sharepoint2010无法连接到配置数据库。
    多选框加和单选框一样的控制,只能选一个
    Windows Server 2008 网站访问PHP响应慢的解决方法
    Windows下的PHP安装文件线程安全和非线程安全的区别
    Apache+PHP 环境上传文件配置
    出现 HTTP Error 503. The service is unavailable 错误
    IIS7 上传 下载文件大小限制的设置
    php 错误信息配置
    新篇章
    面向对象
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5324527.html
Copyright © 2011-2022 走看看