SP122 STEVE - Voracious Steve

题意翻译

Problem

Steve和他的一个朋友在玩游戏,游戏开始前,盒子里有 n个甜甜圈,两个人轮流从盒子里抓甜甜圈,每次至少抓 1个,最多抓m个。

最后一次将当盒子的甜甜圈抓完的人是这一轮游戏胜利者,他可以将所有抓到的甜甜圈吃完,另外一个人是这轮的失败者,他抓到的所有甜甜圈要重新放到盒子里。

下一轮游戏由上一轮的失败者开始抓,游戏继续。直到若干轮后,所有的甜甜圈被吃完,游戏结束。

游戏的目标是吃到尽量多的甜甜圈。游戏最开始,由Steve先抓,两个人均采用最优策略,请问Steve最多可以吃到多少甜甜圈。

Input Data

第一行输入t,表示有t组测试数据

第2~t行,两个整数n和m(1≤m≤n≤100)

Output Data

一行,一个整数,表示Steve最多可以吃到多少个甜甜 圈。

题目描述

Steve and Digit bought a box containing a number of donuts. In order to divide them between themselves they play a special game that they created. The players alternately take a certain, positive number of donuts from the box, but no more than some fixed integer. Each player's donuts are gathered on the player's side. The player that empties the box eats his donuts while the other one puts his donuts back into the box and the game continues with the "loser" player starting. The game goes on until all the donuts are eaten. The goal of the game is to eat the most donuts. How many donuts can Steve, who starts the game, count on, assuming the best strategy for both players?

Task

Write a program that:

  • reads the parameters of the game from the standard input,
  • computes the number of donuts Steve can count on,
  • writes the result to the standard output.

输入输出格式

输入格式:

The input begins with the integer t, the number of test cases. Then t test cases follow.

For each test case the first and only line of the input contains exactly two integers n and m separated by a single space, 1 <= m <= n <= 100 - the parameters of the game, where n is the number of donuts in the box at the beginning of the game and m is the upper limit on the number of donuts to be taken by one player in one move.

输出格式:

For each test case the output contains exactly one integer equal to the number of donuts Steve can count on.

输入输出样例

输入样例#1:

1
5 2

输出样例#1:

3

思路

\(a[all][one][tho]\)表示总共有\(all\)个甜甜圈,现在轮到的人已经取了\(one\)个甜甜圈,另一个人取了\(tho\)个甜甜圈,现在轮到的人最多能取到的甜甜圈数。

我们用记搜方式实现。

当\(all=0\)时,直接返回0。

当\(all\not=0\)时,我们枚举取的个数,从中选出最大值。

一些边界、细节请看代码。

代码

#include<bits/stdc++.h>
using namespace std; int n, m;
int a[205][205][205]; int SG( int all, int one, int tho ){
if ( all == 0 ) return 0;
if ( a[all][one][tho] ) return a[all][one][tho];
int ans(0);//ans为找出的最大值
for ( int i = 1; i <= min( m, all - one - tho ); ++i ){
if ( one + tho + i == all ) ans = max( ans, all - SG( tho, 0, 0 ) );//取完了,把没取到最后一个的人的甜甜圈拿来继续取
else ans = max( ans, all - SG( all, tho, one + i ) );//没取玩,继续取
}
return a[all][one][tho] = ans;//记录答案
} int main(){
int T;
scanf( "%d", &T );
while( T-- ){
memset( a, 0, sizeof a );//每次的m都不同,所以别忘了初始化
scanf( "%d%d", &n, &m );
printf( "%d\n", SG( n, 0, 0 ) );
}
return 0;
}

「SP122」STEVE - Voracious Steve 解题报告的更多相关文章

  1. 洛谷 P4714 「数学」约数个数和 解题报告

    P4714 「数学」约数个数和 题意(假):每个数向自己的约数连边,给出\(n,k(\le 10^{18})\),询问\(n\)的约数形成的图中以\(n\)为起点长为\(k\)的链有多少条(注意每个点 ...

  2. 「NOI2013」树的计数 解题报告

    「NOI2013」树的计数 这什么神题 考虑对bfs重新编号为1,2,3...n,然后重新搞一下dfs序 设dfs序为\(dfn_i\),dfs序第\(i\)位对应的节点为\(pos_i\) 一个暴力 ...

  3. 「NOI2016」优秀的拆分 解题报告

    「NOI2016」优秀的拆分 这不是个SAM题,只是个LCP题目 95分的Hash很简单,枚举每个点为开头和末尾的AA串个数,然后乘一下之类的. 考虑怎么快速求"每个点为开头和末尾的AA串个 ...

  4. 「NOI2016」循环之美 解题报告

    「NOI2016」循环之美 对于小数\(\frac{a}{b}\),如果它在\(k\)进制下被统计,需要满足要求并且不重复. 不重复我们确保这个分数是最简分数即\((a,b)=1\) 满足要求需要满足 ...

  5. 「FJOI2018」领导集团问题 解题报告

    「FJOI2018」领导集团问题 题意:给你一颗\(n\)个点的带点权有根树,选择一个点集\(S\),使得点集中所有祖先的点权$\le \(子孙的点权,最大化\)|S|$(出题人语死早...) 一个显 ...

  6. 「SP25784」BUBBLESORT - Bubble Sort 解题报告

    SP25784 BUBBLESORT - Bubble Sort 题目描述 One of the simplest sorting algorithms, the Bubble Sort, can b ...

  7. 「Luogu」[JSOI2007]字符加密 解题报告

    题面 思路: 作为一个后缀数组的初学者,当然首先想到的是后缀数组 把\(s\)这个串首尾相接,扩展为原来的两倍,就能按后缀数组的方法处理 证明: 神仙一眼就看出这是后缀的裸题,我这个蒟蒻想了半天想不出 ...

  8. 「P5004」专心OI - 跳房子 解题报告

    题面 把\(N\)个无色格子排成一行,选若干个格子染成黑色,要求每个黑色格子之间至少间隔\(M\)个格子,求方案数 思路: 矩阵加速 根据题面,这一题似乎可以用递推 设第\(i\)个格子的编号为\(i ...

  9. 「CF242E」XOR on Segment 解题报告

    题面 长度为\(n\)的数列,现有两种操作: 1.区间异或操作 2.区间求和操作 对于每个查询,输出答案 思路: 线段树+二进制拆位 线段树区间修改一般使用的都是懒标记的方法,但是对于异或,懒标记的方 ...

  10. 「USACO08JAN」电话线Telephone Lines 解题报告

    题面 大意:在加权无向图上求出一条从 \(1\) 号结点到 \(N\) 号结点的路径,使路径上第 \(K + 1\) 大的边权尽量小. 思路: 由于我们只能直接求最短路,不能记录过程中的具体的边--那 ...

随机推荐

  1. Strange Way to Express Integers

    I. Strange Way to Express Integers 题目描述 原题来自:POJ 2891 给定 2n2n2n 个正整数 a1,a2,⋯,ana_1,a_2,\cdots ,a_na​ ...

  2. day8_python网络编程(实验版本)

    1.简单的套接字通信 1.1.服务端 import socket # 买手机 phone = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # 插 ...

  3. C. Tokitsukaze and Duel 前缀维护

    枚举每一个连续的K的第一个位置,如果是先手胜利,那么前[1 , i-1 ]和[ i+k , n ]区间要么全是0,要么全是1 如果能够平局,那么肯定是[1,i-1],以及[ i+k , n]中有两种情 ...

  4. Tensorflow中tf.ConfigProto()详解

    参考Tensorflow Machine Leanrning Cookbook tf.ConfigProto()主要的作用是配置tf.Session的运算方式,比如gpu运算或者cpu运算 具体代码如 ...

  5. codeforces1249-div3

    A B C 等比数列的性质,前面的i项的和,不会超过第i+1项 D 有若干个区间,要求每一个点被区间覆盖的次数不能超过k个.问移除的最少的区间的数目. 贪心: 若某个点被覆盖了k次以上,那么肯定是移除 ...

  6. Python数据可视化matplotlib和seaborn

    Python在数据科学中的地位,不仅仅是因为numpy, scipy, pandas, scikit-learn这些高效易用.接口统一的科学计算包,其强大的数据可视化工具也是重要组成部分.在Pytho ...

  7. Vue 路由的嵌套使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. java引用变量类型转换

    向上转型(子类→父类):(自动完成) 父类名称 父类对象 = 子类实例 ; 向下转型(父类→子类):(强制完成) 子类名称 子类对象 = (子类名称)父类实例 ; 对象名   instanceof  ...

  9. codeforce 382 div2 E —— 树状dp

    题意:给一棵n个结点的无根树染色,求使每个结点距离为k的范围内至少有一个被染色的结点的总染色方法数目 分析:首先我们定义: 对于结点v, 如果存在一个黑色结点u距离v不超过k,则结点v被“控制” 首先 ...

  10. 2018-8-10-用-sim-卡加密保护资金

    title author date CreateTime categories 用 sim 卡加密保护资金 lindexi 2018-08-10 19:16:52 +0800 2018-2-13 17 ...