• 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;
    }
  • 相关阅读:
    分布式文件系统FastDFS详解
    DRF的@action装饰器
    django给视图添加缓存功能
    django自带的django.core.mail模块实现发邮件的功能
    ltsdangerous加密解密
    简单搞懂OAuth2.0
    django使用用户名或手机号码登录
    Spring --- 异常处理机制
    Javascript基于对象三大特征 -- 冒充对象
    SQL--相关子查询 与 非相关子查询
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5324527.html
Copyright © 2020-2023  润新知