Light oj 1031 Easy Game(记忆化)

COMSOL仿真教程—激光烧蚀 本例使用二维模型,将来自激光的入射热通量模拟为金属表面上空间分布的热源,从而得到金属的烧蚀过程和瞬态温度分布。 阅读详情

1031 - Easy Game
Time Limit: 2 second(s)Memory Limit: 32 MB

You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more numbers from the left or right end of the array but cannot take from both ends at a time. He can take as many consecutive numbers as he wants during his time. The game ends when all numbers are taken from the array by the players. The point of each player is calculated by the summation of the numbers, which he has taken. Each player tries to achieve more points from other. If both players play optimally and player A starts the game then how much more point can player A get than player B?

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case contains a blank line and an integer N (1 ≤ N ≤ 100) denoting the size of the array. The next line contains N space separated integers. You may assume that no number will contain more than 4digits.

Output

For each test case, print the case number and the maximum difference that the first player obtained after playing this game optimally.

Sample Input

Output for Sample Input

2

 

4

4 -10 -20 7

 

4

1 2 3 4

Case 1: 7

Case 2: 10

 


SPECIAL THANKS: JANE ALAM JAN (DATASET)





#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define bug printf("hihi\n")

#define eps 1e-8

typedef long long ll;

using namespace std;
#define INF 0x3f3f3f3f
#define N 105

int a[N];
int sum[N];
bool vis[N][N];
int dp[N][N];
int n;

int dfs(int s,int e)
{
    if(vis[s][e]) return dp[s][e];
    vis[s][e]=true;
    if(s>e) return 0;
    dp[s][e]=-INF;
    int all=sum[e]-sum[s-1];

    for(int i=s;i<=e;i++)
    {
        dp[s][e]=max(dp[s][e],all-dfs(i+1,e));
    }

    for(int i=e;i>=s;i--)
        dp[s][e]=max(dp[s][e],all-dfs(s,i-1));
   return dp[s][e];
}

int main()
{
    int i,j,t,ca=0;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            sum[i]=sum[i-1]+a[i];
        }
        memset(vis,false,sizeof(vis));
        dfs(1,n);
        printf("Case %d: %d\n",++ca,dp[1][n]*2-sum[n]);
    }
    return 0;
}







大模型备案避坑指南:如何设计符合TC260标准的评估测试题集? 本文深入探讨了如何设计符合TC260标准的大模型评估测试题集,以顺利通过备案。文章从解构标准核心逻辑出发,详细阐述了题集设计的工程化流程、核心原则与常见误区,并提供了模拟真实对抗的高阶测试策略与度量分析方法,旨在帮助企业构建一套能真实反映模型安全水位、有效规避风险的评估体系。 阅读详情

相关推荐

centos 添加新硬盘,对根目录扩容

本地安装了虚拟机,系统为centos7,使用过程中,渐渐地发现磁盘容量不够用了,于是在虚拟机中新增了一块硬盘。 进入系统内查看: sdb是新增的硬盘,大小为40g。 接下来有两种方式,一种是普通方式直接挂载。https://blog.youkuaiyun.com/qq_39314099/article/details/106200322 这样的话只有在挂载点的目录下操作才能使用到这个新硬盘,不是很理想。 还有一种方式lvm,逻辑卷管理的方式。 LVM简单介绍: 它是 Linux 下对磁盘分区进行管

qq_39314099的博客 1万+

light oj 1031(区间dp入门)

Description You are playing a two player game. Initially there areninteger numbers in an array and playerAandBget chance to take them alternatively. Each player can take one or more n...

weixin_30773135的博客 153

基于STM32的3D打印机控制

通过本项目,我们成功搭建了一个基础的3D打印机控制系统,能够控制步进电机和加热元件。这为使用STM32开发功能丰富的3D打印机提供了基础,您可以在此基础上继续扩展功能,如增加LCD显示、SD卡存储、联网控制等功能。在这个项目中,我们将使用STM32微控制器开发一个基础的3D打印机控制系统。通过控制步进电机、加热元件和温度传感器,我们将实现一个简单的FDM(熔融沉积制造)3D打印机控制。- 检查PWM信号的生成功能,确认加热元件的控制逻辑是否正常。- 增加适当的滤波和校准算法,以提高温度读取的准确性。

2401_88938661的博客 1502

lightoj 1031 - Easy Game(区间DP)

You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more numbers from the left or

SSimpLe_Y的博客 1142

从零到一:海外短剧成品系统源码搭建流程详解及APP+H5交付服务

在当今全球化的数字娱乐浪潮中,海外短剧市场以其独特的文化魅力和广阔的受众基础,正逐渐成为内容创作者与平台运营者争相布局的新蓝海。我为了紧跟时代的发展我翻看了大量的文章,偶然间看到了一篇文章点进去发现他们是专业做短剧开发的,总结下来在这篇文章里分享给大家。

liangyill_的博客 907

手把手教你用Cadence仿真12bit SAR ADC:从电路图到FFT频谱分析(含Simc 18mmrf工艺文件)

本文详细介绍了使用Cadence仿真12bit SAR ADC的全流程,包括电路搭建、仿真环境配置、瞬态仿真优化及FFT频谱分析。基于Simc 18mmrf工艺文件,提供从电路图到性能验证的实战指南,特别分享工程实践中的排错技巧和优化策略,帮助工程师高效完成ADC设计验证。

weixin_30832405的博客 405

1031 - Easy Game 简单区间DP

1031 - Easy Game   You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more num...

pxlsdz的博客 644

麻雀搜索算法(SSA)详解:从鸟群智能到优化实践

麻雀搜索算法(SSA)是一种新型群智能优化算法,模拟麻雀群体的觅食行为和反捕食机制。该算法将优化问题转化为麻雀群体对食物源的搜索过程,通过发现者、加入者和警戒者的角色分工实现高效优化。SSA具有原理新颖、参数合理、收敛快速等特点,在函数优化、工程设计和机器学习等领域展现出良好应用前景。算法通过数学模型模拟麻雀的觅食策略,包括发现者全局探索、加入者局部开发和警戒者危险预警机制,有效平衡了全局搜索与局部开发能力。SSA相比传统优化算法具有更好的收敛性和优化效果。

qq_42212808的博客 1072

C - Easy Game

Description You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more numbers f

努力奋斗,为明天,为梦想,无怨无悔 656

勇攀数字高峰

摘要:该题目要求在数字地形图中寻找从最低点到最高点的所有严格递增登山路径。采用DFS深度优先搜索结合回溯算法,通过标记已访问位置并检查高度差限制(0<diff≤maxDiff)来遍历所有可能路径。算法首先确定起点(最低点)和终点(最高点),然后进行DFS搜索,每步移动需满足四个方向的合法移动且高度严格递增。最终输出符合条件的路径总数。提供了C++、Java和Python三种实现方案。

面试高手的博客 621

华为OD机试 新系统真题 【数字系统转换器】

华为OD机试 新系统真题【数字系统转换器】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【数字系统转换器】多语言题解。

qq_45776114的博客 540

lightoj 1031 被区间dp虐哭...看题解才学会

You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more numbers from the left or

NineFailure的博客 2839

4位无符号比较器设计

4位无符号比较器设计

好好学习,天天向上 7891

区间dp||记忆化搜索 Game of Sum UVA - 10891 or Light OJ 1031---Easy Game(区间DP)

区间dp||记忆化搜索 Game of Sum UVA - 10891 or Light OJ 1031---Easy Game(区间DP)

axuhongbo的博客 316

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

LightOJ1031-Easy Game-记忆化搜索+博弈

You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more numbers from the left or...

Nothing_but_Fight的博客 276

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

lightoj刷题日记

yep.

ONE MORE TRY 1176

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

lightoj1031 - Easy Game【区间dp】

1031 - Easy Game     PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You are playing a two player game. Initially there are n intege

走一步再走一步 720

UVA 10891 - Game of Sum(区间dp)

Problem E Game of Sum Input File: e.in Output: Standard Output   This is a two player game. Initially there are n integer numbers in an array and players A and B get chance to take them alternati

Remilia's 1726

LightOj 1031 区间dp

F - Easy Game LightOJ - 1031You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or m...

keep coding 405

三天一题-14-Add Two Numbers

题目地址:[leetcode-Median of Two Sorted Arrays]

yanguo110的博客 189

lightoj 1031 - Easy Game 【区间dp】

题目链接:lightoj 1031 - Easy Game 1031 - Easy Game PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You are playing a two player game. Initially there are n intege

世界很大 778

light oj 1031

C - Easy Game Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description You are playing a two player game. Initially there are n integer numbers

猿的进化 503

Divide two integer

class Solution(object): def divide(self, dividend, divisor): max_int = 2147483647 divd,divs = abs(dividend),abs(divisor) res = 0 while divd>=divs: a,i =

pyb的博客 626

436 sum of all integer numbers

sum of all integer numbers 时间限制:1000 ms  |  内存限制:65535 KB 难度:0 描述Your task is to find the sum of all integer numbers lying between 1 and N inclusive. 输入There are multiple test cases.

希望的专栏 931

HDU 4770 Lights Against Dudely

Problem Description Harry: "But Hagrid. How am I going to pay for all of this? I haven't any money." Hagrid: "Well there's your money, Harry! Gringotts, the wizard bank! Ain't no safer place. Not

左眼皮跳跳 1655

HDU 5325 Crazy Bobo(思路+dfs 记忆化)

Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 612    Accepted Submission(s): 189 Problem Description Bobo has a tree,

左眼皮跳跳 1209
上一篇: Light oj 1025 (区间dp)
下一篇: Light oj 1032 - Fast Bit Calculations(数位dp)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值