HDU 4111 Alice and Bob 记忆化搜索

MATLAB不能识别已安装的visual studio 2015解决方法 首先,对于MATLAB识别已经安装的vs版本通过命令: mex -setup 下图为本电脑下同时安装的两个visual studio 如果搞清楚MATLAB识别电脑上安装vs的过程,可通过命令: mex -setup -v MATLAB输出识别编译器的整个过程。其中HKLM和HKCU分别是注册表中的HKEY_CURRENT_USER,HKEY_LOCAL_MA…的缩写,MATLAB没有找到对应编译器是由于注册表里没有对应信息(主要是文件路径,C++编译器的路径),或者在注册表里存在该信息,但是找不到 阅读详情

Alice and Bob are very smart guys and they like to play all kinds of games in their spare time. the most amazing thing is that they always find the best strategy, and that's why they feel bored againand again. They just invented a new game, as they usually did.

The rule of the new game is quite simple. At the beginning of the game, they write down N random positive integers, then they take turns (Alice first) to either:

  1. Decrease a number by one.
  2. Erase any two numbers and write down their sum.

Whenever a number is decreased to 0, it will be erased automatically. the game ends when all numbers are finally erased, and the one who cannot play in his(her) turn loses the game.

Here's the problem: Who will win the game if both use the best strategy? Find it out quickly, before they get bored of the game again!

Input 

The first line contains an integer T (1$ \le$T$ \le$4000), indicating the number of test cases.

Each test case contains several lines.

The first line contains an integer N (1$ \le$N$ \le$50).

The next line contains N positive integers A1...AN (1$ \le$Ai$ \le$1000), represents the numbers they write down at the beginning of the game.

Output 

For each test case in the input, print one line: `Case #X: Y', where X is the test case number (starting with 1) and Y is either "Alice" or "Bob".

Sample Input 

3
3
1 1 2
2
3 4
3
2 3 5

Sample Output 

Case #1: Alice
Case #2: Bob
Case #3: Bob

  N个数,两人轮流选一个数,可以减1,也可以加到另外一个数上。如果减到0这个数就消失了。

  大于1的数最后肯定是要加到一个数上去的,因为关键在于1可以改变胜负状态,因为1的时候可以选择减为0或者加到另一个数上,这样相当于走了一步和没走。所以一开始必胜的那个人肯定不会让另一个人把这些不为1的数在1处操作的。所以这些数等价于一个合并数,合并的时候要加上移动过去的那一步。

  dp[a][b]表示有a个1,剩下的那个合并数的值为b。进行记忆化搜索,搜索各种可能情况,要考虑完全。

#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<algorithm>
#define eps 1e-9
#define MAXN 50010
#define MAXM 55
#define MAXNODE 100010*27
#define MOD 999983
typedef long long LL;
using namespace std;
int T,N,dp[MAXM][MAXN];
int DP(int a,int b){
    int& ans=dp[a][b];
    if(ans!=-1) return ans;
    if(b==1) return ans=DP(a+1,0);  //如果合并数为1,就相当于多了个1,没有合并数
    if(a>0&&!DP(a-1,b)) return ans=1;   //把一个1减掉
    if(b>0&&!DP(a,b-1)) return ans=1;   //把合并数减一
    if(a>0&&b&&!DP(a-1,b+1)) return ans=1;  //在合并数大于0的情况下把一个1加到合并数上
    if(a>1&&(b&&!DP(a-2,b+3)||!b&&!DP(a-2,2))) return ans=1;    //把一个1加到另一个1上变成2,如果合并数存在,把2和合并数合并,因为移动算1次,所以是b+3,如果合并数不存在,2就相当于一个新的合并数
    return ans=0;
}
int main(){
    freopen("in.txt","r",stdin);
    int cas=0;
    memset(dp,-1,sizeof(dp));
    scanf("%d",&T);
    while(T--){
        scanf("%d",&N);
        int one=0,sum=0,t;
        for(int i=0;i<N;i++){
            scanf("%d",&t);
            if(t==1) one++;
            else sum+=t+1;
        }
        if(sum) sum--;
        printf("Case #%d: ",++cas);
        if(DP(one,sum)) printf("Alice\n");
        else printf("Bob\n");
    }
    return 0;
}



EEG/ERP新手必看:5本神经科学入门书籍推荐(附高清PDF下载) 本文为EEG/ERP研究新手推荐5本神经科学入门书籍,涵盖认知神经科学、数据分析、ERP技术等核心内容。特别推荐《认知神经科学—关于心智的生物学》和《事件相关电位基础》,这些书籍不仅提供理论框架,还包含实用案例和MATLAB代码,帮助研究者快速掌握脑电研究技术。附高清PDF下载,适合实验室小组学习。 阅读详情

相关推荐

制造业批次管理中双计量单位动态转换的实践指南

本文详细介绍了制造业批次管理中双计量单位动态转换的实践指南,特别是在SAP系统中的配置与操作步骤。通过实际案例展示了如何解决采购与生产部门计量单位不一致的问题,提升物料管理效率。重点讲解了批次特性配置、移动类型调整及常见问题排查方法,适用于金属加工、化工等多个行业。

weixin_29228203的博客 173

hdu4111Alice and Bob+SG博弈

Description Alice and Bob are very smart guys and they like to play all kinds of games in their spare time. The most amazing thing is that they always find the best strategy, and that’s why they feel

xtulollipop 713

Bartender 2021破解版安装教程:手把手教你从下载到激活(附详细步骤图)

本文详细介绍了BarTender 2021专业版的安装与高效应用指南,从基础配置到高级条码设计,帮助用户快速掌握标签设计与打印技术。内容涵盖安装步骤、标签模板创建、数据连接与批量打印技巧,以及高级功能如安全策略与自动化集成,适合零售、物流、制造等行业用户提升工作效率。

p4q5r6s7t的博客 2785

Hdu 4111 Alice and Bob(博弈+记忆化搜索)

题目链接 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1587    Accepted Submission(s): 575 Problem Description Alice and

madaidao的专栏 513

SIwave仿真手册——信号完整性仿真之S参数的提取(二)

上一篇简单了讲述了软件的各个操作界面,本次博客更新关于的仿真,因为第二章完整的内容比较多,所以分成好几篇博客进行分享。

luohuo9844的博客 1万+

电机系列(1) - foc最基本原理、clark变换 、park变换、附代码

什么是FOC? FOC(Field-Oriented Control),直译是磁场定向控制,也被称作矢量控制 (VC,Vector Control) ,是目前无刷直流电机(BLDC)和永磁同步电机(PMSM)高效控制的最优方法之一。FOC旨在通过精确地控制磁场大小与方向,使得电机的运动转矩平稳、噪声小、效率高,并且具有高速的动态响应。 简单来说就是,FOC是一种对无刷电机的驱动控制方法,它可以让我们对无刷电机进行 “像素级” 控制,实现很多传统电机控制方法所无法达到的效果。 因为所谓的“矢量控制”其实就是

nepqiu的博客 7万+

hdu 4111 Alice and Bob 记忆化搜索 博弈论

Alice and Bob Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4111 Description Alice and Bob are very smart guys and they like to play all kinds of g...

weixin_34110749的博客 176

IMU、INS、GNSS与组合导航:从原理到工程实践全解析

在自动驾驶、无人机和机器人等智能系统的定位方案中,IMU、INS、GNSS和组合导航常被混为一谈,但它们在硬件层级、数据特性和误差机制上截然不同。IMU作为惯性测量单元,以百赫兹以上频率输出加速度和角速度;INS基于IMU完成姿态、速度与位置的递推解算,却因积分累积误差而随时间漂移;GNSS提供绝对位置,但易受遮挡和干扰。组合导航通过卡尔曼滤波将两者融合,实现短期不飘、长期不偏的连续定位,这正是高精度导航系统的技术底座。工程落地时,从IMU标定、Allan方差分析到相机/LiDAR与IMU外参标定,再到松耦

weixin_29193259的博客 394

HDU-4111 Alice and Bob(博弈 + 记忆化搜索)

Alice and Bob are very smart guys and they like to play all kinds of games in their spare time. The most amazing thing is that they always find the best strategy, and that's why they feel bored again and again. They just invented a new game, as they usuall

yo_bc的博客 619

【WRF数据准备】气象驱动数据-ERA5再分析数据(Copernicus)

【WRF数据准备】气象驱动数据-ERA5再分析数据

WW、forever的博客 5561

基于方差分解分析气象/水文干旱驱动因素(含MATLAB全代码)

简介基于方差分解方法分析气象/水文干旱驱动因素

WW、forever的博客 807

hdu4111 Alice and Bob---sg dp记忆化求sg

Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 598    Accepted Submission(s): 207 Problem Description Alice and Bob are

Shirley 1625

C++怎么学?零基础也可以,一份完整学习路线图助你搞定!

提供一条清晰、系统且实践导向的C++学习路径。从基础语法、面向对象、泛型编程、异常处理,逐步深入STL、智能指针、并发编程等现代C++高级特性。无论是新手还是希望提升,通过系统学习与项目实践,助您将理论知识转化为实际解决问题的能力。

Lion_Long的博客 4067

HDU 4111 Alice and Bob (博弈)11年成都现场赛

转载请注明出处,谢谢 http://blog.csdn.net/ACM_cxlove?viewmode=contents           by---cxlove 可惜没有机会去现场做,不过当时肯定是不会。 题意:有N堆石头,可以把两堆合成一堆,也可以把一堆去掉一个。 由于总数不变,最终总是要一个个拿完。那么有机会获胜的一方,肯定是先要把所有的合在一起,那么最终就拼奇偶数了。所以双方都

窝不是爱酱,喵~~~~ 6735

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Alice and Bob HDU - 4111(SG函数,NP定理)

Alice and Bob are very smart guys and they like to play all kinds of games in their spare time. The most amazing thing is that they always find the best strategy, and that’s why they feel bored again ...

tomjobs的博客 516

OV9734 DATASHEET,完整规格书

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

HDU 4111--Alice and Bob

来源:http://acm.hdu.edu.cn/showproblem.php?pid=4111 题意:有n堆石子,Alice和bob轮流进行游戏,游戏有两种操作:1、从其中一堆拿走一个石子,2、选两堆石子合并。每人每次只能选两种操作中的一种,谁拿到最后一个石子谁赢。 分析:由于总数不变,最终总是要一个个拿完。那么有机会获胜的一方,肯定是先要把所有的合在一起,那么最终就拼奇偶数了。所以双方都

Xcockroach的专栏 614

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

HDU 4111 Alice and Bob

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4111 题意:有n堆石子,每堆有ai个,现在可以选择一堆拿走一个,或者合并两堆。问谁能赢。 思路: 如果全部的堆数都大于1,那么一定是把石子全部合并后一个个取走,因为输的人没法一次取走一堆,而赢的人每次把最少的合并起来。 dp[i][j]表示有i堆为1的石子,j是

DS-K的博客 503

HDU 4111Alice and Bob(博弈+记忆化)

题意:有n堆石子,一次可以拿走一个石子,或者把一堆石子放在另一个石子上。不能再次操作的人输Alice先拿。问谁赢 思路:当石子个数大于1时,可以把他们放到一堆里+1次的操作数。石子数为1时,单独考虑。 设所有只有一个石子的是A堆,其他的石子可以合并的设为B堆。 每一次操作有: 1、把A堆 的两个石子合并。加入到B堆。 2、把B堆的石子减1 3、把A堆的一个石子加入的B堆 4、把A堆的

binwin20 2121

HDU 4111 Alice and Bob (博弈[记忆话搜索])

题意: 给你n 堆石子,两种操作: 1. 任选一堆石子, 数目减一, 如果为0 删除这一堆。 2. 任选两堆石子进行合并。 最后不能操作的人输掉。 问谁能赢? 思路: 记忆话搜索博弈,第一次见到。 状态找的比较巧妙把。 把所有的石子堆数分成两类。 数量为1, 数量为2, 和数量大于等于3的奇数,和数量大于等于4的偶数。 因为大于等于3 的奇数,你取一步 他取一步 ,效

aozil_yang的博客 422

hdu 4111 Alice and Bob(中档博弈题)★ ★

1.每堆部是1的时候,是3的倍数时输否则赢; 2.只有一堆2其他全是1的时候,1的堆数是3的倍数时输否则赢; 3.其他情况下,计算出总和+堆数-1,若为偶数,且1的堆数是偶数,则一定输; 4.不在上述情况下则赢。 #include int main() { int js=0; int _case,i,n,x; int flag1,flag2,flag,sum;

Ezereal的博客 514

hdu 4111 Alice and Bob(中档博弈题)

copy VS study 1.每堆部是1的时候,是3的倍数时输否则赢; 2.只有一堆2其他全是1的时候,1的堆数是3的倍数时输否则赢; 3.其他情况下,计算出总和+堆数-1,若为偶数,且1的堆数是偶数,则一定输; 4.不在上述情况下则赢。 #include<stdio.h> int main() { int js=0; int _case,i,n...

weixin_34259559的博客 202

对于SG函数的理解

首先是NIM游戏,N堆石子,两个人轮流拿,可以拿一堆或者一堆中的一部分。最后谁不能操作

4929

hdu3980 Paint Chain SG函数

Problem Description Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one pl

886

uva10561 - Treblecross SG定理

Treblecross Input: Standard Input Output: Standard Output Time Limit: 4 Seconds   Treblecross is a two player gamewhere the goal is to get three X in a row on a one-dimensional board. At the sta

712

uva12163 - Addition-Subtraction Game SG函数 状态压缩

You and your friend are playing a 2 player game.The game is played in a graph of V vertices. The vertices are numberedfrom 0 to V-1. The graph has some directed edges. But the graphdoes not contain

712

uva1378 - A Funny Stone Game SG函数

The funny stone game is coming. There are n piles of stones,numbered with 0, 1, 2,..., n - 1. Two persons pick stones in turn.In every turn, each person selects three piles of stones numberedi, j, k

665
上一篇: uva1378 - A Funny Stone Game SG函数
下一篇: uva1386 - Cellular Automaton 循环矩阵
小小小小葱
博客等级 码龄14年 22粉丝 266原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址