Bomber Man wants to bomb an Array.
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 556 Accepted Submission(s): 190
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.
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
Hint:
Sample 1:
Sample 2:
Bomber Man wants to bomb an Array.
給一個長度爲 N 的一維格子和一些炸彈的位置,請你計算 “最大總破壞指數”。 每個炸彈都有向左和向右的破壞力,如果一個炸彈向左和向右的破壞力分別爲 L 和 R, 那麼該炸彈將炸燬 L+R+1 個格子(左邊L個,炸彈所在格子,右邊R個)。 破壞指數的計算方式爲:所有炸彈炸燬的格子數的乘積。假設第 i 個炸彈炸燬了 Xi個格子, 那麼總破壞指數就是 X1∗X2∗....Xm。 現在告訴你每個炸彈的位置,你需要計算 最大的總破壞指數,注意:每個格子最多隻允許被炸一次。
多組測試數據,第一行爲一個整數 T(T≤11)。 每組測試數據第一行爲兩個整數 N,M(1≤N≤2000,1≤M≤N),分別表示格子總數和炸彈總數 。 第二行是 M 個互不相同的數表示每個炸彈所在的位置。
對於每組測試數據,輸出 floor(10^6 * log2(最大破壞指數)) (floor表示向下取整)。
2 10 2 0 9 10 3 0 4 8
4643856 5169925
Sample 1 :
Sample 2:
題意:有一行n個的格子,其中m個格子有炸彈,然後炸彈可以向左向右炸,範圍自定義,但是不能重複炸同一個格子。然後每個炸彈對應一個炸的格子數,所有炸彈的對應格子數乘積,然後運算一下。
思路:DP求解,對於每個炸彈,可以炸的範圍L,R是不確定的,但是一定在左右兩個炸彈所在位置範圍內,所以可以枚舉一下可以炸的範圍,dp[i]用來記錄對於第i個位置,累計可以得到的最大值。
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#define ll __int64
#define MOD 1000000007
using namespace std;
int a[2222];
double dp[2222];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
memset(dp,0,sizeof dp);
for(int i=1; i<=m; i++)
{
scanf("%d",&a[i]);
a[i]++;
}
sort(a+1,a+m+1);
a[m+1]=n+1;
for(int i=1; i<=m; i++)
{
for(int j=a[i-1]+1; j<=a[i]; j++)
{
for(int k=a[i]; k<=a[i+1]-1; k++)
{
dp[k]=max(dp[k],dp[j-1]+(log(k-j+1.0)/log(2.0)));
}
}
}
ll ans=floor(1e6*dp[n]);
printf("%I64d\n",ans);
}
return 0;
}