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;
}
目录
相关文章
|
存储 算法 Python
算法专题1——动态规划 Dynamic Programming,DP
算法专题1——动态规划 Dynamic Programming,DP
101 0
|
1月前
|
存储 Python
动态规划(Dynamic Programming, DP)
动态规划(Dynamic Programming, DP)
31 2
|
7月前
|
机器学习/深度学习 Java
hdu-2680-Choose the best route(dijkstra)
hdu-2680-Choose the best route(dijkstra)
35 0
UVa872 - Ordering(拓扑排序)
UVa872 - Ordering(拓扑排序)
61 0
|
开发框架 .NET
poj 3468 A Simple Problem with Integers线段树区间修改
题目意思很简单,有N个数,Q个操作, Q l r 表示查询从l到r 的和,C l r v 表示将从l到r 的值加上v,明显的线段树,不知道线段树的人肯定暴力,肯定超时,哈哈!!
34 0
UVa11420 - Chest of Drawers(动态规划)
UVa11420 - Chest of Drawers(动态规划)
49 0
UVa668 - Parliament(贪心)
UVa668 - Parliament(贪心)
59 0
HDU7050.Link with Limit(有向图tarjan找环)
HDU7050.Link with Limit(有向图tarjan找环)
149 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 .
208 0
|
机器学习/深度学习
HDU-2680,Choose the best route(Dijkstra)
HDU-2680,Choose the best route(Dijkstra)