BestCoder Round #77 (div.1) Bomber Man wants to bomb an Array. Hdu5653

题意:给一个长度为 的一维格子和一些炸弹的位置,请你计算 “最大总破坏指数”。

每个炸弹都有向左和向右的破坏力,如果一个炸弹向左和向右的破坏力分别为 和 R,

那么该炸弹将炸毁 L + R + 1个格子(左边L个,炸弹所在格子,右边R个)。

破坏指数的计算方式为:所有炸弹炸毁的格子数的乘积。假设第 个炸弹炸毁了 X_i个格子,

那么总破坏指数就是 X_1 * X_2 * .... X_m

现在告诉你每个炸弹的位置,你需要计算 最大的总破坏指数,注意:每个格子最多只允许被炸一次。(n<=2000)


思路:dp,dp[i][j]表示到了第i个位置,该位置选择的R的位置为j,那么状态转移方程为dp[i][j]=max(dp[i-1][k]+log2(k-j)),k表示第i-1个位置选择的R的位置。


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2001;
double dp[2][maxn];
int a[maxn];

int main(){
    int _,n,m;
    scanf("%d",&_);
    while(_--){
        scanf("%d%d",&n,&m);
        for(int i=1;i<=m;i++)
            scanf("%d",&a[i]),a[i]++;
        sort(a+1,a+m+1);
        a[0]=0,a[m+1]=n+1;
        memset(dp,0,sizeof(dp));
        int flag=0;
        for(int i=1;i<=m;i++){
            for(int j=a[i-1];j<=a[i]-1;j++)//上一个的右边
                for(int k=a[i];k<=a[i+1]-1;k++)//这一个的右边
                    dp[flag^1][k]=max(dp[flag^1][k],dp[flag][j]+log(k-j)/log(2));
            flag^=1;
        }
        printf("%lld\n",(long long)floor(dp[flag][n]*1000000));
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Solve the problem with c++ code, and give your code: Ack Country has N cities connected by M one-way channels. The cities occupied by the rebels are numbered 1, while the capital of Ack country is numbered N. In order to reduce the loss of effective force, you are permitted to use self-propelled bombers for this task. Any bomber enters the capital, your job is done. This seems simple enough, but the only difficulty is that many cities in Ack Country are covered by shields. If a city is protected by a shield, all shield generators that maintain the shield need to be destroyed before the bomber can enter or pass through the city. Fortunately, we know the cities where all the shield generators are located, and which cities' shields are being charged. If the bomber enters a city, all of its shield generators can be destroyed instantly. You can release any number of Bombermen and execute any command at the same time, but it takes time for bombermen to pass through the roads between cities. Please figure out how soon you can blow up Ack Nation's capital. The clock is ticking. Input: Two positive integers N,M in the first row. The next M lines, each with three positive integers, indicate that there is a road leading from the city to the city. It takes w time for the bomber to cross this road. Then N lines, each describing a city's shield. The first is a positive integer n, representing the number of shield generators that maintain shields in the city. Then n_i city numbers between 1 and N, indicating the location of each shield generator. In other words, if your bomber needs to enter the city, the bomber needs to enter all the entered cities in advance. If n_i=0, the city has no shields. Guarantee n_i=0.Output: a positive integer, the minimum time to blow up the capital. e.g., Input: 6 6 1 2 1 1 4 3 2 3 3 2 5 2 4 6 2 5 3 2 0 0 0 1 3 0 2 3 5, Output: 6.
最新发布
06-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值