Topcoder SRM565 DIV2 500分-c++

Manao在途中遇到战斗力和贿赂需求不同的怪物。他必须贿赂怪物以增加战斗力,防止被攻击。问题转化为寻找经过所有怪物的最低贿赂总费用。这可以通过动态规划来解决,状态定义为(i, j),表示在第i个怪物处拥有j战斗力。最优解是找到money(n, j)的最小值。" 79620311,7242986,RLlib:可组合和可扩展的强化学习库,"['强化学习', '深度学习', '机器学习库', '分布式计算', '超参数调整']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Statement

 Manao is traversing a valley inhabited by monsters. During his journey, he will encounter several monsters one by one. The scariness of each monster is a positive integer. Some monsters may be scarier than others. The i-th (0-based index) monster Manao will meet has scariness equal to dread[i].

Manao is not going to fight the monsters. Instead, he will bribe some of them and make them join him. To bribe the i-th monster, Manao needs price[i] gold coins. The monsters are not too greedy, therefore each value in price will be either 1 or 2.

At the beginning, Manao travels alone. Each time he meets a monster, he first has the option to bribe it, and then the monster may decide to attack him. A monster will attack Manao if and only if he did not bribe it and its scariness is strictly greater than the total scariness of all monsters in Manao's party. In other words, whenever Manao encounters a monster that would attack him, he has to bribe it. If he encounters a monster that would not attack him, he may either bribe it, or simply walk past the monster.



Consider this example: Manao is traversing the valley inhabited by the Dragon, the Hydra and the Killer Rabbit. When he encounters the Dragon, he has no choice but to bribe him, spending 1 gold coin (in each test case, Manao has to bribe the first monster he meets, because when he travels alone, the total scariness of monsters in his party is zero). When they come by the Hydra, Manao can either pass or bribe her. In the end, he needs to get past the Killer Rabbit. If Manao bribed the Hydra, the total scariness of his party exceeds the Rabbit's, so they will pass. Otherwise, the Rabbit has to be bribed for two gold coins. Therefore, the optimal choice is to bribe the Hydra and then to walk past the Killer Rabbit. The total cost of getting through the valley this way is 2 gold coins.

You are given the vector <int>s dread and price. Compute the minimum price Manao will pay to safely pass the valley.

Definition

 
Class:MonstersValley2
Method:minimumPrice
Parameters:vector <int>, vector <int>
Returns:int
Method signature:int minimumPrice(vector <int> dread, vector <int> price)
(be sure your method is public)

Limits

 
Time limit (s):2.000
Memory limit (MB):64

Constraints

-dread will contain between 1 and 20 elements, inclusive.
-Each element of dread will be between 1 and 2,000,000,000, inclusive.
-price will contain between the same number of elements as dread.
-Each element of price will be either 1 or 2.

Examples

0) 
 
{8, 5, 10}
{1, 1, 2}
Returns: 2
The example from the problem statement.
1) 
 
{1, 2, 4, 1000000000}
{1, 1, 1, 2}
Returns: 5
Manao has to bribe all monsters in the valley.
2) 
 
{200, 107, 105, 206, 307, 400}
{1, 2, 1, 1, 1, 2}
Returns: 2
Manao can bribe monsters 0 and 3.
3) 
 
{5216, 12512, 613, 1256, 66, 17202, 30000, 23512, 2125, 33333}
{2, 2, 1, 1, 1, 1, 2, 1, 2, 1}
Returns: 5
Bribing monsters 0, 1 and 5 is sufficient to pass safely.

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.     

题目大意:

Manao要依次经过一些怪物,每个怪物具有两个属性战斗力和贿赂所需的金钱,一开始Manao没有战斗力,他通过贿赂怪兽使其成为自己的战斗力,要是Manao当前经过的怪兽的战斗力比Manao的战斗力高,怪兽就会攻击他,Manao就必须贿赂怪兽,反之,Manao可以选择贿赂或直接过去,求经过一系列怪兽所花费的最少的金钱数。

此题经分析为动态规划,要求的最优解为最少钱数,而状态为(i,j),表示当前经过第i个怪兽时战斗力为j,money(i,j)->money(i+1,j+dread[i])+price[i]或money(i+1,j),答案是money(n,j)中最小值。

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#define INF 0xfffffff
using namespace std;

class MonstersValley2
{
public:
	typedef map<int, int> MAP;
	int minimumPrice(vector<int> dread, vector<int> price)
	{	
		size_t n = dread.size();
		vector<MAP> m(n);
		m[0][dread[0]] = price[0];
		int i = 1, k = INF;
		while (i<n)
		{
			k = INF;
			for (MAP::iterator it = m[i-1].begin(); it != m[i-1].end(); ++it)
			{
				if (it->first < dread[i])
				{
					int t;
					t = m[i][it->first + dread[i]] = it->second + price[i];
					if (k > t)
						k = t;
				}

				else
				{
					int t;
					t = m[i][it->first] = it->second;
					m[i][it->first + dread[i]] = it->second + price[i];
					if (k > t)
						k = t;
				}
			}
			++i;
		}
		return k;
	}
};


在机器人操作系统(ROS)中,机器视觉是机器人感知和理解周围环境的关键技术。robot_vision功能包专注于这一领域,集成了多种视觉处理技术,包括摄像头标定、OpenCV库应用、人脸识别、物体跟踪、二维码识别和物体识别,极大地拓展了ROS在视觉应用方面的能力。 摄像头标定:作为机器视觉的基础,摄像头标定用于消除镜头畸变并获取相机的内参和外参。在ROS中,camera_calibration包提供了友好的用户界面和算法,帮助计算相机参数矩阵,为后续的图像校正和三维重建提供支持。 OpenCV:OpenCV是一个广泛使用的开源计算机视觉库,在ROS中扮演着重要角色。robot_vision功能包可能包含OpenCV的示例代码和节点,涵盖图像处理、特征检测、模板匹配和图像割等功能,这些功能对机器人视觉系统至关重要。 人脸识别:ROS中的人脸识别结合了图像处理和机器学习技术。robot_vision可能集成了基于OpenCV的人脸检测算法,如Haar级联类器或Adaboost方法,甚至可能包含深度学习模型(如FaceNet或SSD),帮助机器人实现人脸的识别和跟踪,提升人机交互能力。 物体跟踪:物体跟踪使机器人能够持续关注并追踪特定目标。在ROS中,通常通过卡尔曼滤波器、粒子滤波器或光流法实现。robot_vision功能包可能包含这些算法的实现,助力机器人完成动态目标跟踪任务。 二维码识别:二维码是一种高效的信息编码方式,常用于机器人定位和导航。ROS中的二维码包可用于读取和解析二维码,而robot_vision可能进一步封装了这一功能,使其更易于集成到机器人系统中。 物体识别:作为机器视觉的高级应用,物体识别通常涉及深度学习模型,如YOLO、SSD或Faster R-CNN。robot_vision功能包可能包含预训练的模型和对应的ROS节点,使机器人能够识别环境中的特
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值