题目链接:uva 10688 - The Poor Giant
题目大意:给出n和k,表示n个苹果,排成一列,重量分别是i+k,i为对应的第几个苹果,现在在这n个苹果中,有1个苹果是甜的,假设该苹果的序号为x,那么序号小于x的即为苦的,大于x的为酸的。求一个吃苹果的序列,要求可以找出甜得苹果,并且要求所有可能下的吃苹果质量和最小。
解题思路:记忆化搜索,dp[i][j]表示说甜得苹果在i~j之间时,需要的最小质量。但是因为在搜索的过程中,值还和先前吃得苹果质量有关,但是说因为要考虑所有情况下的质量和,所以可以将其单独出来计算,m*len。
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 505;
const int INF = 0x3f3f3f3f;
int n, k, dp[N][N];
int solve (int l, int r, int m) {
int s = (r-l+1)*m;
if (dp[l][r] != INF)
return s + dp[l][r];
if (r == l) return s;
int& ans = dp[l][r];
for (int i = l; i <= r; i++) {
int u = i+k;
if (i != l) u += solve(l, i-1, i+k);
if (i != r) u += solve (i+1, r, i+k);
ans = min(ans, u);
}
return ans + s;
}
int main () {
int cas;
scanf("%d", &cas);
for (int i = 1; i <= cas; i++) {
memset(dp, INF, sizeof(dp));
scanf("%d%d", &n, &k);
printf("Case %d: %d\n", i, solve(1, n, 0));
}
return 0;
}
分享到:
相关推荐
20--[巨人的花园 the giant`s garden].zip源码scratch2.0 3.0编程项目源文件源码案例素材20--[巨人的花园 the giant`s garden].zip源码scratch2.0 3.0编程项目源文件源码案例素材20--[巨人的花园 the giant`s garden...
The.Giant.Black.Book.of.Computer.Viruses.1995.PDF.eBook-HannahMontana Get to know computer virus.
杰克巨人 我的游戏 Jack The Giant 在 google play 上发布的完整源代码。
开源项目-forestgiant-stela.zip,On-premises distributed service discovery written in GO
开源项目-forestgiant-sliceutil.zip,go-slice实用程序包
decry viruses and call for secrecy about the technology they employ, while curiously giving you just enough technical details about viruses so you don’t feel like you’ve been cheated. Rather, this ...
宋雨琦 - Giant.ncm
Welcome to the world of social business, where the creative vision of the entrepreneur is applied to today's most serious problems: feeding the poor, housing the homeless, healing the sick, and ...
资源管理器(巨型杀手机器人Mark-2) 这是一个包含Java ... 该代码用于扩展到更大的项目,并且可能是Giant Killer Robot Mk-1代码改版的一部分。 建立 Windows 10.0-AMD64 Gradle4.4 Java 1.8 Arduino IDE 1.8.9
RED.GIANT.TOONIT.V1.1.0-INTERNAL-VR
Red Giant TrapCode Suite v12.0 ======================== Trapcode Mir 1.0 ---------------------------- 9023-9561-1234-8610-6394 TrapCode 3D Stroke v2.6.1 ------------------------- 8291-8797-2567-6362...
营销策划 -Giant KONE市场策略规划.pptx
气体自引力对气态巨行星在原恒星盘中打开空隙及迁移过程的影响,张辉,刘慧根,目的:研究气体自引力对气态巨行星和气体盘相互作用的影响,包括行星打开空隙和轨道迁移过程。方法:采用了一维和二维流体力学数�
通过java去访问网页,并且修改网站里面的js,通过debug 修改 js来快速抓取网页。
Giant520称重模块是向工业控制等相关领域的称重控制器。它集称重,RS485/RS232通信接口(Modbus协议)于一体。称重通道前端信号处理采用高精度的24位专用A/D转换器,具有输入信号范围宽,分辨率高,零点和满载温漂小的...
在ubuntu18.04LTS版本下安装GIANT软件的过程
red giant for AE 3.0
The 21st century is the society of information and new technologies: it wouldn’t be possible without the enormous software industry that is the foundation for it. However, software developers don’t ...
python库,解压后可用。 资源全名:giant_plugins-0.3.3-py3-none-any.whl
资源来自pypi官网。 资源全名:giant_plugins-0.3.3-py3-none-any.whl