当前位置: 首页 > article >正文

洛谷 P10108 [GESP202312 六级] 闯关游戏 题解

传送门

动态规划。注意,一些关卡的得分可能是负数。

AC Code

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[105],b[10005],c[10005];
int ans=-1e9;
int n,m;
int fun(int q){
	if(q>=n) return 0;
	if(c[q]!=-1e9){
		return c[q];
	}
	for(int i=0;i<m;i++){
		c[q]=max(c[q],b[q]+fun(q+a[i]));
	}
	return c[q];
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
for(int i=0;i<m;i++){
	cin>>a[i];
}for(int i=0;i<n;i++){
	cin>>b[i];
	c[i]=-1e9;
}
	cout<<fun(0);
	return 0;
}


http://www.kler.cn/a/597643.html

相关文章:

  • Android Studio控制台中文乱码解决方案
  • Webpack vs Vite:深度对比与实战示例,如何选择最佳构建工具?
  • LeetCode热题100精讲——Top1:两数之和【哈希】
  • 如何编写一个Spring Boot Starter
  • Ubuntu YOLO5 环境安装
  • UI设计中的大数据可视化:解锁数据背后的秘密
  • 基于深度学习的图像分割项目实践:从理论到应用
  • 基于WebAssembly的浏览器密码套件
  • 【技术选型】三大 Python Web 框架全面对比
  • React学习(进阶)
  • github如何为开源项目作出贡献
  • 为什么后端路由需要携带 /api 作为前缀?前端如何设置基础路径 /api?
  • Python推导式深入解析
  • React Native进阶(六十一): WebView 替代方案 react-native-webview 应用详解
  • 使用外部事件检测接入 CDH 大数据管理平台告警
  • 除自身以外数组的乘积——面试经典150题(力扣)
  • 基于Python+Ollama DeepSeek与MySQL进行数据分析探索
  • Rocky9.5基于sealos快速部署k8s集群
  • OpenHarmony子系统开发 - 电源管理(二)
  • 二进制求和 力扣67