题目链接:
Bomber Man wants to bomb an Array.
Time Limit: 4000/2000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 382 Accepted Submission(s): 114
Problem 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.
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
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)).
Hint:
Sample 1:
Sample 2:
Hint:
Sample 1:
Sample 2:
Sample Input
2
10 2
0 9
10 3
0 4 8
Sample Output
4643856
5169925
题意:
xi为第i个炸弹炸的格子的数目,问x1*x2*..xm的最大值是多少;
思路:
比赛的时候直接没怎么想这题,后来看别人博客说是dp,然后发现是一个区间dp,在两个相邻格子的中间选取这两个炸弹的分界点,找到使ans最大的点;还有就是函数库里面没有log2的函数,可以用换底公式log2(n)=log10(n)/log(2);
AC代码:
/* Problem : 5653 ( Bomber Man wants to bomb an Array. ) Judge Status : Accepted RunId : 16703569 Language : G++ Author : 2014300227 */ #include <bits/stdc++.h> using namespace std; int n,m,a[2004]; double dp[2002][2002]; const double N=1000000; int main() { int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i=0;i<=m;i++) for(int j=0;j<=n;j++) dp[i][j]=0; for(int i=1;i<=m;i++) { scanf("%d",&a[i]); a[i]++; } a[0]=0; a[m+1]=n+1; sort(a,a+m+2); for(int i=1;i<a[2];i++) { dp[1][i]=log10(i*1.0)/log10(2.0)*N; } for(int i=2;i<=m;i++) { for(int j=a[i];j<a[i+1];j++) { for(int k=a[i-1];k<a[i];k++) { dp[i][j]=max(dp[i][j],dp[i-1][k]+log10((j-k)*1.0)/log10(2)*N); } } } int ans=(int)(dp[m][n]); printf("%d\n",ans); } return 0; }