UVa11157 - Dynamic Frog(动态规划)

简介: UVa11157 - Dynamic Frog(动态规划)
#include <cstdio>#include <cstring>#include <algorithm>#include <cstdlib>usingnamespacestd;
constintN=110;
intmemo[N][N];
structRock{
charkind;
intsize;
};
Rockrock[N];
intn, d;
boolinput();
intsolve();
intdp(inti, intj);
intmain()
{
#ifndef ONLINE_JUDGEfreopen("d:\\OJ\\uva_in.txt", "r", stdin);
#endif // ONLINE_JUDGEintt;
scanf("%d", &t);
for (inti=1; i<=t; i++) {
input();
intans=solve();
printf("Case %d: %d\n", i, ans);
    }
return0;
}
boolinput()
{
scanf("%d", &n);
rock[0].kind='B', rock[0].size=0;
rock[n+1].kind='B';
scanf("%d", &rock[n+1].size);
for (inti=1; i<=n; i++) {
scanf(" %c-%d", &rock[i].kind, &rock[i].size);
    }
returntrue;
}
intsolve()
{
memset(memo, 0xff, sizeof(memo));
returndp(0, 0);
}
intdp(inti, intj)
{
int&res=memo[i][j];
if (res!=-1) returnres;
res=1<<30;
if (i>n&&j>n) returnres=0;
if (i<=j) {
for (intt=i; t<=n+1; t++) {
if (t==j&&rock[t].kind!='B') continue;
res=min(res, max(rock[t].size-rock[i].size, dp(t, j)));
        }
    } else {
for (intt=j; t<=n+1; t++) {
if (t==i&&rock[t].kind!='B') continue;
res=min(res, max(rock[t].size-rock[j].size, dp(i, t)));
        }
    }
returnres;
}
目录
相关文章
|
10月前
|
存储 算法 Python
算法专题1——动态规划 Dynamic Programming,DP
算法专题1——动态规划 Dynamic Programming,DP
83 0
|
23天前
|
算法 C++
POJ 3740 Easy Finding题解
这篇文章提供了一个使用舞蹈链(Dancing Links)算法解决POJ 3740 "Easy Finding" 问题的C++代码实现,该问题要求找出矩阵中能够使每一列都恰好包含一个1的行集合。
UVa872 - Ordering(拓扑排序)
UVa872 - Ordering(拓扑排序)
55 0
|
网络架构
POJ 3250 Bad Hair Day、POJ 2796 Feel Good(单调栈)
POJ 3250 Bad Hair Day、POJ 2796 Feel Good(单调栈)
UVa11420 - Chest of Drawers(动态规划)
UVa11420 - Chest of Drawers(动态规划)
45 0
UVa668 - Parliament(贪心)
UVa668 - Parliament(贪心)
48 0
|
人工智能 BI
[UVA 1599] Ideal Path | 细节最短路
Description New labyrinth attraction is open in New Lostland amusement park. The labyrinth consists of n rooms connected by m passages. Each passage is colored into some color ci .
196 0
HDU-1097,A hard puzzle(快速幂)
HDU-1097,A hard puzzle(快速幂)
|
Go
HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)
HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)
100 0
|
Java BI 机器学习/深度学习