uva10891Game of sum

题意:经典的取石子游戏是这样的:有一堆石子,A、B两个人轮流取,每次取一颗,只能从边上取,每个石子有相应的价值,A、B两人都想使得自己的价值最多,两个人足够聪明,问最后价值分别是多少

本题则是可以取多颗,但仍然只能从一侧取得

分析:状态转移方程

best[i][j]=sum[i][j]-min(best[i][j-k],best[i+k][j], 0);{1<=k=j-i+1}.

使用了记忆化的方法,O(n3),书上说有进一步的优化,不过当前数据下已经很快了(64ms)

代码:

View Code
 1 #include <stdio.h>
 2 #include <iostream>
 3 #include <string.h>
 4 using namespace std;
 5 const int MAXN = 100 + 10;
 6 #define DEBUG
 7 int min(int a, int b){
 8     return a<b?a:b;
 9 }
10 int s[MAXN], a[MAXN], d[MAXN][MAXN], vis[MAXN][MAXN], n;
11 int dp(int i, int j){
12     if(vis[i][j]) return d[i][j];
13     vis[i][j]=1;
14     int m=0, k;
15     for(k=i+1; k<=j; k++) m=min(m, dp(k, j));
16     for(k=i; k<j; k++) m=min(m, dp(i, k));
17     d[i][j]=s[j]-s[i-1]-m;;
18     return d[i][j];
19 }
20 int main(){
21 #ifndef DEBUG
22     freopen("in.txt", "r", stdin);
23 #endif
24     while(scanf("%d", &n)!=EOF && n){
25         s[0]=0;
26         int i;
27         for(i=1; i<=n; i++){
28             scanf("%d", &a[i]);
29             s[i] = s[i-1] + a[i];
30         }
31         memset(vis, 0, sizeof(vis));
32         printf("%d\n", 2*dp(1,n)-s[n]);
33     }
34     return 0;
35 }

 

 

转载于:https://www.cnblogs.com/zjutzz/archive/2013/02/14/2911230.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/274361.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

用户体验设计师能为seo做_用户体验设计师可以从产品设计历史中学到什么

用户体验设计师能为seo做Many things have changed from tool design in the prehistoric era to today’s digital product design. However, we can see surprisingly many similarities. Especially when it comes down to one particular aspect: usability.从史前时代的工…

orton效果_如何使图片发光:Orton效果

orton效果Have you ever seen an impossibly dream-like landscape photo? One with a slow burning, glowing sunset. That’s really the best way to describe it, the image looks as if it’s glowing. You might be thinking, “wow, I wish I was that good and could …

UVA10785 The Mad Numerologist

虽然是sorting的压轴&#xff0c;但是比起前面真心水题。这个专题结合前面string的很多&#xff0c;排序相对简单了&#xff0c;qsort基本解决。 题目&#xff1a; The Mad Numerologist Numerology is a science that is used by many people to find out a mans personality,…

苹果人机交互指南_苹果人机界面设计指南的10个见解

苹果人机交互指南重点 (Top highlight)I’ve been developing an IOS app for the past few months and have been constantly referring to Apple’s Human Interface Design Guidelines. I would consider it a must-read for any aspiring or current UI/UX designer.在过去…

也来学学插件式开发

上一家公司有用到插件式开发来做一个工具箱&#xff0c;类似于QQ电脑管家&#xff0c;有很多工具列表&#xff0c;点一下工具下载后就可以开始使用了。可惜在那家公司待的时候有点短&#xff0c;没有好好研究一下。现在有空&#xff0c;自己在网上找了些资料&#xff0c;也来试…

同态加法_我对同态的想法

同态加法Early February, I uploaded this shot onto Dribbble. Nothing fancy –– just two screens experimenting with “2月初&#xff0c;我将这张照片上传到Dribbble。 没什么幻想–只有两个屏幕在尝试“ Neumorphism,” or soft UI. Little did I know that this post…

php内核探索

引自&#xff1a;http://www.nowamagic.net/librarys/veda/detail/1285 SAPI:Server Application Programming Interface 服务器端应用编程端口。研究过PHP架构的同学应该知道这个东东的重要性&#xff0c;它提供了一个接口&#xff0c;使得PHP可以和其他应用进行交互数据。 本…

hp-ux锁定用户密码_UX设计101:用户研究-入门需要了解的一切

hp-ux锁定用户密码这是什么&#xff1f; (What is this?) This session is part of a learning curriculum that I designed to incrementally skill up and empower a team of Designers and Researchers whose skillset and ways of working needed to evolve to keep up wi…

extjs6 引入ux_关于UX以及如何摆脱UX的6种常见误解

extjs6 引入uxDo you ever browse social media, internet, or talk to colleagues and hear them say something UX related you disagree with so much that you just want to lecture them on the spot?您是否曾经浏览过社交媒体&#xff0c;互联网或与同事交谈&#xff0c…

Cocos2D-HTML5开源2D游戏引擎

http://www.programmer.com.cn/12198/ Cocos2D-HTML5是基于HTML5规范集的Cocos2D引擎的分支&#xff0c;于2012年5月发布。Cocos2D-HTML5的作者林顺将在本文中介绍Cocos2D-HTML5的框架、API、跨平台能力以及强大的性能。Cocos2D-HTML5是Cocos2D系列引擎随着互联网技术演进而产生…

illustrator下载_Illustrator笔工具练习

illustrator下载Adobe Illustrator is a fantastic vector creation tool and you can create a lot of things without ever using the Pen Tool. However, if you want to use Illustrator at its full potential, I personally believe that you need to master and become …

怎么更好练习数位板_如何设计更好的仪表板

怎么更好练习数位板重点 (Top highlight)Dashboard noun \ˈdash-ˌbȯrd\ A screen on the front of a usually horse-drawn vehicle to intercept water, mud, or snow.仪表盘 名词\ ˈdash-ˌbȯrd \\通常在马拉的车辆前部的屏幕&#xff0c;用来拦截水&#xff0c;泥或雪。…

学习正则表达式

deerchao的blog Be and aware of who you are. 正则表达式30分钟入门教程 来园子之前写的一篇正则表达式教程&#xff0c;部分翻译自codeproject的The 30 Minute Regex Tutorial。 由于评论里有过长的URL,所以本页排版比较混乱,推荐你到原处查看,看完了如果有问题,再到这里来提…

人物肖像速写_去哪儿? 优步肖像之旅

人物肖像速写In early 2018, the Uber brand team started a rebranding exercise, exploring a fresh take on what it means to be a global transportation and technology company. A new logo was developed in tandem with a bespoke sans-serif typeface called Uber Mo…

hp-ux锁定用户密码_我们如何简化925移动应用程序的用户入门— UX案例研究

hp-ux锁定用户密码Prologue: While this is fundamentally a showcase of our process in the hopes of helping others, it’s also a story about the realism of limitations when working with clients and how we ultimately were able to deliver a product the client w…

微信公众号无需二次登录_您无需两次解决问题-您需要一个设计系统

微信公众号无需二次登录重点 (Top highlight)The design system concept can be differently defined according to each person’s background. Designers may say that a design system is a style guide while developers may say it is UI standards, or specs, or even as…

视觉工程师面试指南_选择正确视觉效果的终极指南

视觉工程师面试指南When it comes to effective data visualization, the very first and also the most critical step is to select the right graph/visual for the data that you want to present. With a wide range of visualization software that is available offerin…

问题反馈模板_使用此模板可获得更好,更有价值的UX反馈

问题反馈模板Feedback is an important part of UX design. To improve the work you do you need to be able to give and receive feedback. Receiving valuable feedback is for a very large part up to you.反馈是UX设计的重要组成部分。 为了改进您的工作&#xff0c;您需…

iofd:文件描述符_文字很重要:谈论设计时18个有意义的描述符

iofd:文件描述符As designers, many of us think we’re just visual creatures. But creating visuals is only half of the job. The other half is verbal communication — actually talking about design. Whether we’re showcasing our own work, giving or receiving c…

保护程序猿滴眼睛-----修改VS 2008 编辑器颜色 (修改 chrome浏览器的背景色)

前几天更改了 chrome 的背景色后&#xff0c;虽然有些地方看起来不和谐&#xff0c;想百度的首页&#xff0c;显示出了大快的图片区域&#xff0c;但是&#xff0c;整体感觉这个颜色设置真的对眼睛有一定保护作用。。。 所以&#xff0c;再顺便修改一下 经常用的 vs2008 编辑器…