HDU 5653 (DP)
来源:互联网 发布:手机淘宝我要开店 编辑:程序博客网 时间:2024/05/18 22:42
Bomber Man wants to bomb an Array.
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 143 Accepted Submission(s): 43
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 capabilityL and some right destruction capability R which means if a bomb is dropped at i th location it will destroy L blocks on the left and R blocks on the right.
Number of Blocks destroyed by a bomb isL+R+1
Total Impact is calculated as product of number of blocks destroyed by each bomb.
Ifi th 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
Number of Blocks destroyed by a bomb is
Total Impact is calculated as product of number of blocks destroyed by each bomb.
If
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 IntegersN and M which are the number of locations and number of bombing locations respectivly.
Second line containsM distinct integers specifying the Bombing Locations.
1 <= N <= 2000
1 <= M <= N
First line two Integers
Second line contains
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
210 20 910 30 4 8
Sample Output
46438565169925
题意:一个炸弹能够炸掉包括自己的一个连续区间内的格子,一个炸弹的威力用它炸掉的区间长度表示.n个
格子中给出m个炸弹的位置,求所有炸弹的威力之积的最大值.
由于题目要求输出的威力之积的对数,可以用乘积的对数转化为对数的和来减少精度误差.假设DP[i]表示i之
间炸完的最大价值对数和,那么DP[i] = max (DP[j]+log(j-i)/log(2)),能够转移的前提是区间[i,j-1]之间恰好存
在一个炸弹.
#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <queue>using namespace std;#define maxn 2111double dp[maxn];//dp[i]表示i之前炸完的最大价值int n, m;int pos[maxn], sum[maxn];double f (int x) { double ans = log (1.0*x)/log (2); return ans;}int main () { //freopen ("in.txt", "r", stdin); int t; scanf ("%d", &t); while (t--) { memset (sum, 0, sizeof sum); scanf ("%d%d", &n, &m); for (int i = 1; i <= m; i++) { int x; scanf ("%d", &x); sum[x+1] = 1; } for (int i = 1; i <= n; i++) sum[i] = sum[i-1]+sum[i]; memset (dp, 0, sizeof dp); for (int i = 1; i <= n+1; i++) { for (int j = 1; j < i; j++) if (sum[i-1]-sum[j-1] == 1) dp[i] = max (dp[i], dp[j]+f (i-j)); } printf ("%lld\n", (long long)((floor)(1000000.0*dp[n+1]))); } return 0;}
0 0
- HDU 5653 (DP)
- HDU DP
- DP? HDU
- DP? HDU
- DP? HDU
- 【dp】HDU
- 【dp】HDU
- 【dp】 HDU
- DP? HDU
- HDU 1003 && HDU 1231 DP
- hdu 1058 DP
- HDU 1069 dp
- HDU 1024(DP)
- hdu 1257 dp+贪心
- HDU 1087(DP)
- HDU 1506(DP)
- hdu 2844 DP 背包
- HDU 1087 简单DP
- java学习笔记16.3.26
- 零基础学习前端-从bootstrap开始(一)
- static变量
- Android中菜单的使用
- Request的getParameter和getAttribute方法的区别
- HDU 5653 (DP)
- 笔记
- Android蓝牙总结
- 码农小汪-struts2学习10-上传下载文件
- 关于字符串String,你所需要注意的细节
- 1015 of greedy strategy
- 密码学基础笔记-(1)
- 网站被黑检测-网页挂马及暗链检测
- OC阅读笔记三:动态绑定