poj 2904 The Mailboxes Manufacturers Problem( 区间dp)
来源:互联网 发布:关于单片机的毕业设计 编辑:程序博客网 时间:2024/06/14 07:05
题目链接:
点击打开链接
题目大意:
给出k个油桶,给出油桶被炸掉的最小限度的上限,问在最坏情况下需要炸药最少的决策条件下需要的炸药。
题目分析:
首先定义状态dp[i][j][k]是还剩i个油桶且当前需要进行判断的区间是j-k的时候的最优值,这样的话dp[i][j][k]的情况一定是最坏的我们不能决定,但我们能够进行决策,也就是我们能够确定在当前状态下选择检验的量,对于每个选择的检验量,会有两种情况,第一种情况是油桶的最小承受限度小于检验量,那么这个油桶就炸掉了,那么就是转移到dp[i-1][j][t-1]+t,另一种情况最小承受限度大于检验量,那么这个油桶还在,同样我们的检测区间也变小了,也就是转移到dp[i][t+1][k],因为是在最坏情况下,所以要在两种情况中取较大的,然后因为要通过决策得到最优解,也就是最小值,所以枚举t求解最小值
代码如下:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define MAX 107#define INF 1<<29using namespace std;int n,k,m;int dp[20][MAX][MAX];void init ( ){ memset ( dp , 0 , sizeof (dp)); for ( int i = 1 ; i < MAX ; i++ ) for ( int j = i ; j < MAX ; j++ ) dp[1][i][j] = (j-i+1)*(i+j)/2; for ( int i = 2 ; i <= 10 ; i++ ) for ( int j = 1 ; j <= 100 ; j++ ) for (int k = j; k > 0 ; k-- ) { dp[i][k][j] = INF; for ( int t = k ; t <= j ; t++ ) dp[i][k][j] = min ( dp[i][k][j] , max ( dp[i-1][k][t-1]+t , dp[i][t+1][j]+t )); }}int main (){ init(); scanf ( "%d" , &n ); while ( n-- ) { scanf ( "%d%d" , &k , &m ); printf ( "%d\n" , dp[k][1][m] ); }}
0 0
- poj 2904 The Mailboxes Manufacturers Problem( 区间dp)
- poj 2904 The Mailboxes Manufacturers Problem(DP)
- lightoj-1223-Testing Mailboxes 区间dp
- lightoj 1223 - Testing Mailboxes 区间DP
- 【区间dp】Treats for the Cows POJ
- POJ 3590 The shuffle Problem 置换+DP
- The Counting Problem - POJ 2282 数位dp
- poj 3042 Grazing on the Run(区间DP,三维DP)
- POJ 2282-The Counting Problem(组合数学_区间计数)
- POJ 3042 Grazing on the Run (区间DP)
- poj 3056 The Bavarian Beer Party (区间dp)
- poj 3186 Treats for the Cows (区间dp)
- 【POJ 3186 】Treats for the Cows (区间DP)
- POJ 3186 Treats for the Cows(区间DP)
- poj-3816 Treats for the Cows 【区间DP】
- poj 3186 Treats for the Cows(区间dp)
- poj 3186 Treats for the Cows(区间dp)
- poj 3168 Treats for the Cows 区间dp
- 一次简单的Maven加速构建实战
- 微信平台红包制作基础教程
- 代码审查最佳实践
- 027.Do While 循环语句
- 实训项目
- poj 2904 The Mailboxes Manufacturers Problem( 区间dp)
- C# using简介
- java中的char,short,int,long占几个字节
- javascript(一)
- LintCode 字符串转化成正数(atoi)
- 028.For 循环
- Android多媒体学习七:访问网络上的Audio对应的M3U文件,实现网络音频流的播放
- lua语言实现面向对象编程
- 【一步一步的积累】Neighbourhood Components Analysis