HDU 4597 Play Game(区间dp)

高通ISP模块全解析:从Raw到JPEG的18个关键处理步骤(附避坑指南) 本文全面解析高通ISP模块从Raw到JPEG的18个关键处理步骤,涵盖原始数据预处理、色彩科学处理链、画质增强与降噪等核心环节。通过实战调优经验,揭示ISP架构中的技术原理与工程实践要点,帮助开发者避免常见问题,提升移动影像处理质量。 阅读详情

题目链接:HDU 4597 Play Game

区间dp。

这题没做出来,看了题解说这是区间dp,貌似没做过这种题吧,这几天练练。

dp[x1][y1][x2][y2]表示在第一个堆只剩下x1到y1,第二个区间只剩下x2到y2最多可以取到的数的和。

那么当一个人面对这种状态时候,他有四种状态可以选择,分别是dp[x1 + 1][y1][x2][y2],dp[x1][y1 - 1][x2][y2],dp[x1][y1][x2 + 1][y2],dp[x1][y1][x2][y2 - 1],显然他应该选择这四个最小的那个。

两个sum数组分别表示两堆的前n项和。dp[x1][y1][x2][y2] = sum1[y1] - sum1[x1 -1] + sum2[y2] - sum2[x2 - 1] - min(dp[x1 + 1][y1][x2][y2],dp[x1][y1 - 1][x2][y2],dp[x1][y1][x2 + 1][y2],dp[x1][y1][x2][y2 - 1])),感觉这里挺难理解的。

#include <iostream>
#include <stdio.h>
#include <cstring>

using namespace std;

const int MAX_N = 20 + 3;

int sum1[MAX_N], sum2[MAX_N];
int T, n;
int dp[MAX_N][MAX_N][MAX_N][MAX_N];

int dfs(int x1, int y1, int x2, int y2)
{
    if(x1 > y1 && x2 > y2)
        return 0;
    int &ans = dp[x1][y1][x2][y2];
    if(ans != -1)
        return ans;
    int sum = sum1[y1] - sum1[x1 -1] + sum2[y2] - sum2[x2 - 1];
    if(x1 <= y1)
        ans = max(ans, sum - min(dfs(x1 + 1, y1, x2, y2), dfs(x1, y1 - 1, x2, y2)));
    if(x2 <= y2)
        ans = max(ans, sum - min(dfs(x1, y1, x2 + 1, y2), dfs(x1, y1, x2, y2 - 1)));
    return ans;
}
int main()
{
    scanf("%d", &T);
    while(T--)
    {
        memset(dp, -1, sizeof(dp));
        scanf("%d", &n);
        int temp = 0;
        sum1[0] = sum2[0] = 0;
        for(int i = 1; i <= n; i++)
        {
            scanf("%d", &temp);
            sum1[i] = sum1[i - 1] + temp;
        }
        for(int i = 1; i <= n; i++)
        {
            scanf("%d", &temp);
            sum2[i] = sum2[i - 1] + temp;
        }
        printf("%d\n", dfs(1, n, 1, n));
    }
    return 0;
}



奇迹mu服务端DATA文件解析:从基础配置到高级玩法 本文深入解析奇迹MU服务端DATA文件的核心配置与高级玩法,涵盖基础设置、怪物AI系统、技能战斗机制、副本事件管理及物品商城定制。通过详细示例和实用技巧,帮助开发者掌握从经验倍率调整到动态事件触发的全方位配置方法,实现个性化的私服搭建与运营。 阅读详情

相关推荐

hdu 4597 Play Game(区间dp)

题意 Alice和Bob玩一个游戏,有两个长度为N的正整数数字序列,每次他们两个 只能从其中一个序列,选择两端中的一个拿走。他们都希望可以拿到尽量大 的数字之和,并且他们都足够聪明,每次都选择最优策略。Alice先选择,问 最终Alice拿到的数字总和是多少? 思路 这题应该算是区间dp吧,可以看一下这题的原型: 其他规则都一样,但是只有一个数字序列,也是每次只能拿左右两端的一个数字,问最终Alice拿多少? (这个可以去做uva-10891) 只有一行数字

D_Double's Journey 3034

Autoware.universe部署03:与Carla(二进制版)联调

本文介绍了 Autoware.universe 与 Carla 二进制版的联调过程。Autoware.universe 是一个开源的自动驾驶软件平台,而 Carla 则是一个用于自动驾驶仿真的开源工具。将这两者联调起来可以在仿真环境中测试和验证 Autoware.universe 的功能和性能,为自动驾驶系统的开发和测试提供有力支持。

zardforever123的博客 7369

STM32F103C8T6通过ESP8266连接阿里云物联网平台(附代码)

STM32F103C8T6连接阿里云物联网平台(1)—阿里云lot Studio控制 Web开发 分享一下自己使用stm32f103c8t6通过ESP_01模块连接阿里云物联网平台,实现温湿度上传和控制命令下达的过程,能力有限,用的是最简单的方法,如有错误,多多担待。 一、硬件选型 1、 stm32f103c8t6 2、ESP_01 wifi模块 3、其他 二、硬件连接 WSP_01 STM32F103C8T6 RXD PA2 TXD PA3 RES PA4 VCC 3.3

weixin_A13253323604 3万+

HBuilderX结合Android Studio实现Uniapp安卓Apk高效离线打包指南

本文提供了一份详细的Uniapp安卓Apk离线打包实战指南。通过整合HBuilderX与Android Studio,手把手教你搭建本地编译环境、配置原生工程、执行核心打包流程,并分享快速更新资源和排查常见问题的技巧,助你彻底摆脱云端打包的排队依赖,实现高效、可控的应用构建。

weixin_28835551的博客 559

hdu 4597 Play Game 区间dp

Play Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4597 Description Alice and Bob are playing a game. There are two piles of cards. There are N ...

weixin_30538029的博客 108

OC5021B 100V宽电压输入 LED车灯/大功率照明 DC降压型恒流驱动器

适用于LED大功率汽车大灯/大功率照明 OC5021B 100V宽电压输入 5A电流设计 DC-DC降压型恒流驱动IC

Handsome63841990的博客 2417

HDU 4597 Play Game(DFS,区间DP)

HDU 4597 Play Game(DFS,区间DP)

Dacc123的博客 575

【科技前沿】用深度强化学习优化电网,让电力调度更聪明!

Hey小伙伴们,今天我要跟大家分享一个超级酷炫的技术应用——深度强化学习在电网优化中的典型案例!如果你对机器学习感兴趣,或是正寻找如何用AI技术解决实际问题的方法,这篇分享绝对不容错过!👩‍💻✨

Jacklx888的博客 3247

petalinux2022.2启动文件编译配置

petalinux2021之前的版本里,导入目录components/yocto/下的“environment-setup-aarch64-xilinx-linux” 和 “layers/core/oe-init-build-env”的环境,能使用Yocto的devtool工具。(加入下面内容,先petalinux-build下载完成后才能有源码)制作 BOOT.BIN 启动文件:petalinux-package --boot --fsbl --fpga --u-boot --force。

wangjie36的博客 1391

HDU - 4597 Play Game (博弈 + 区间dp)

Alice and Bob are playing a game. There are two piles of cards. There are N cards in each pile, and each card has a score. They take turns to pick up the top or bottom card from either pile, and the score of the card will be added to his total score. Alice

。 294

Electron vue3 - 使用SerialPort与串口交互教程,计算机串行端口(COM口、USB转串口等)进行通信连接读取或写入Arduino、单片机、PLC、扫码枪、打印机、老式调制解调器!

实战Electron使用SerialPort与串口交互详细全过程,Electron-vue3与串口交互示例,Electron vue使用serialport实现串口交互通讯,Electron-vue使用serialport连接本地串口,electron-vue 台称串口对接 SerialPort,electron串口调试工具,electron+vue+serialport实现串口通信,串口通信serialport使用和调试,electron-vue使用serialport串口通信及踩过的坑(已解决!)ele

🏆 前端领域优质创作者 4641

HDU 4597 - Play Game(区间DP)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=4597 题意:两个序列,两个人每次只能从其中一个序列的两端取一个数,最优策略使得总数值最大。 思路:区间DP,记忆化搜索, dfs(i, j, k, l), 表示第一个序列剩下区间[i,j],第二个序列剩下区间[k,l]的情况下开始拿,最多可以拿多少?    当面临状态dfs(i, j, k, l)

Halo 585

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

HDU-4597 Play Game (区间DP)

设dp[i][j][k][l]表示先手从a数组区间[i,j]中以及b数组区间[k,l]中能选得的最大数字和 则dp[i][j][k][l]可由四个状态转移而来: ①先手拿a[i],由dp[i+1][j][k][l]转移而来,即 a[i]+sum(i+1,j,k,l)-dp[i+1][j][k][l]; ②先手拿a[j],由dp[i][j-1][k][l]转移而来,即 a[j]+sum(i,j-1,k,l)-dp[i][j-1][k][l]; ③先手拿b[k],由dp[i][j][k+1][l]转移而来,即

idealism_xxm的专栏 631

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

hdu 4597 Play Game 记忆化搜索 区间dp

题意: 给你两摞牌,每次可以任意一堆 的牌头或者牌尾抽牌。Alice先抽,Bob后抽,两个人都想抽到最多点数的牌。 做法: dp[az][ay][bz][by]。 az,ay代表第一堆牌左边 和右边 分别抽到第几张了。然后在这个状态下 Bob抽到的点数。 因为dp表示的Bob的点数,所以牌堆里剩余奇数张牌的时候,是Bob抽,要取各种抽法的最大值。如果只剩偶数张牌,那么是Alice抽,要取 各种抽法中 的最小值。

万事屋 931

HDU-4597 Play Game(区间DP)

题意:给定两串长度均为n的数列,两个人轮流取数,可以取两串数列的头或尾元素,求先取者能获得的最大值。明显的四维区间dp,相当于取数游戏的升级版,由小区间拓展到大区间即可。#include&lt;iostream&gt; #include&lt;cmath&gt; #include&lt;cstdio&gt; #include&lt;cstdlib&gt; #include&lt;cstring&g...

Paulliant的博客 305

HDU 4597 Play Game (博弈 + 区间dp)

题意:Alice和Bob玩一个游戏,有两个长度为N的正整数数字序列,每次他们两个 只能从其中一个序列,选择两端中的一个拿走。他们都希望可以拿到尽量大 的数字之和,并且他们都足够聪明,每次都选择最优策略。Alice先选择,问 最终Alice拿到的数字总和是多少?思路:经典区间dp的变形,可以参考这道题:uva-10891 http://blog.youkuaiyun.com/wing_w

普通で歩む 558

hdu-4597 Play Game(区间DP)

Play Game点我找原题Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 888    Accepted Submission(s): 519Problem DescriptionAlice and Bob are playing a g

Nature_Ran的专栏 496

hdu 4597 Play Game (记忆化搜索,区间dp)

题目大意: 有两个人玩取数的游戏,每次只能从两堆数列的两头取一个数,问先取的那个人最大能够获得的数是多少。 解题思路: 有题解说是记忆化搜索,很显然,我用了4维dp保存结果。dp[i][j][k][t] 表示 第一行为第i个数字到第j个数字,第二行为第k个数字到第t个数字的时候,我能够取得的最大值。 这边有个小问题,就是在状态转移的时候,我们要取几种可能状态下的最小值,虽然dp整个表示的是

Gavin的专栏 564

hdu 4597 Play Game (记忆化搜索 区间dp)

#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> using namespace std; int dp[30][30][30][30]; int vis[30][30][30][...

weixin_30315435的博客 96

hdu 4597 Play Game(区间dp,记忆化搜索)

Problem Description Alice and Bob are playing a game. There are two piles of cards. There are N cards in each pile, and each card has a score. They take turns to pick up the top or bottom card fr...

weixin_34144848的博客 77
上一篇: HDU 4496 D-City(并查集)
下一篇: 括号匹配(dp)
小爷永远不死
博客等级 码龄15年 58粉丝 363原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值