Boxes and Stones

Paul and Carole like to play a game with
S stones and B boxes numbered from 1 to
B. Beforebeginning the game they arbitrarily distribute the
S stones among the boxes from 1 to
B - 1, leavingbox B empty. The game then proceeds by rounds. At each round, first Paul chooses a subset
P of the stones that are in the boxes; he may choose as many stones as he wants from as many boxes as he wants, or he may choose no stones at all, in which case
P is empty. Then, Carole decides what to donext: she can either
promote the subset P and
discard the remaining stones (that is, those stones notchosen by Paul in the first step); or she may
discard the subset P and
promote the remaining stones.

To promote a given subset means to take each stone in this subset and move it to the box with thenext number in sequence, so that if there was a stone in this subset inside box
b, it is moved to boxb + 1. To
discard a given subset means to remove every stone in this subset from its corresponding box, so that those stones are not used in the game for the remaining rounds. The figure below shows an example of the first two rounds of a
game.

Paul and Carole play until at least one stone reaches box number
B, in which case Paul wins the game, or until there are no more stones left in the boxes, in which case Carole wins the game. Paulis a very rational player, but Carole is a worthy rival because she is not only extremely good
at this game, but also quite lucky. We would like to know who is the best player, but before that we must first understand how the outcome of a game depends on the initial distribution of the stones. In particular,we would like to know in how many ways the
S stones can initially be distributed among the first B - 1 boxes so that Carole can be certain that she can win the game if she plays optimally, even if Paul never makes a mistake.

Input

Each test case is described using one line. The line contains two integers
S (1S200)
and B(2B100),
representing respectively the number of stones and the number of boxes in the game.

Output

For each test case output a line with an integer representing the number of ways in which the
S stonesmay be distributed among the first
B - 1 boxes so that Carole is certain that she can win the game.Because this number can be very large, you are required to output the remainder of dividing it by109 + 7.

Sample Input

2 3
8 4
42 42

Sample Output

2
0
498467348

题目链接:

option=com_onlinejudge&Itemid=8&category=441&page=show_problem&problem=3970">https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=441&page=show_problem&problem=3970

题目大意:P和C做游戏。有S个石头和B个盒子,他们把S个石头随意的放在1~B-1这些盒子中,P開始从1~B-1中随意的挑选一些石头。C能够决定把P选的石头丢掉让剩下的石头都往右移一格,或者把P选的石头都往右移一个。其它的都丢掉。一旦有一个石头到B盒子中。则P胜。若没有石头了则C胜,问有多少种初始的摆放状态为C的必胜态

题目分析:设dp[i][j][k]为到第i个盒子。用了j个石头,C做完决定后第i个盒子里的石头数为k的必胜态个数。离线计算出全部情况。O(1)查询,先分析P的最优策略,P的目标是尽量多的让石子右移。但是选择权在C手上,因此P的最优策略是尽量一半一半的取,假设在这样的情况下P还是输,那么就是C的必胜态了。dp[i][j][k]状态由三部分转移

dp[i][j][k] = dp[i][j - 1][k - 1] + dp[i - 1][j][2 * k] + dp[i - 1][j][2 * k + 1]

#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
int const MOD = 1e9 + 7;
int const MAX = 105;
ll dp[MAX][2 * MAX][4 * MAX]; void pre()
{
dp[0][0][0] = 1;
for(int i = 1; i <= 100; i++)
for(int j = 0; j <= 200; j++)
for(int k = 0; k <= 200; k++)
dp[i][j][k] = (dp[i][j - 1][k - 1] + dp[i - 1][j][k * 2] + dp[i - 1][j][k * 2 + 1]) % MOD;
} int main()
{
pre();
int s, b;
while(scanf("%d %d", &s, &b) != EOF)
printf("%lld\n", dp[b][s][0]);
}

UVa 12525 Boxes and Stones (dp 博弈)的更多相关文章

  1. UVA 10404 Bachet's Game(dp + 博弈?)

    Problem B: Bachet's Game Bachet's game is probably known to all but probably not by this name. Initi ...

  2. codevs 1421 秋静叶&秋穣子(树上DP+博弈)

    1421 秋静叶&秋穣子   题目描述 Description 在幻想乡,秋姐妹是掌管秋天的神明,作为红叶之神的姐姐静叶和作为丰收之神的妹妹穰子.如果把红叶和果实联系在一 起,自然会想到烤红薯 ...

  3. hdu6199 gems gems gems dp+博弈

    /** 2017 ACM/ICPC Asia Regional Shenyang Online 解题报告 题目:hdu6199 gems gems gems 链接:http://acm.hdu.edu ...

  4. UVA.10066 The Twin Towers (DP LCS)

    UVA.10066 The Twin Towers (DP LCS) 题意分析 有2座塔,分别由不同长度的石块组成.现在要求移走一些石块,使得这2座塔的高度相同,求高度最大是多少. 问题的实质可以转化 ...

  5. POJ 2068 NIm (dp博弈,每个人都有特定的取最大值)

    题目大意: 有2n个人,从0开始编号,按编号奇偶分为两队,循环轮流取一堆有m个石子的石堆,偶数队先手,每个人至少取1个,至多取w[i]个,取走最后一个石子的队伍输.问偶数队是否能赢. 分析: 题目数据 ...

  6. UVA 1482 - Playing With Stones(SG打表规律)

    UVA 1482 - Playing With Stones 题目链接 题意:给定n堆石头,每次选一堆取至少一个.不超过一半的石子,最后不能取的输,问是否先手必胜 思路:数值非常大.无法直接递推sg函 ...

  7. UVA 10003 Cutting Sticks 区间DP+记忆化搜索

    UVA 10003 Cutting Sticks+区间DP 纵有疾风起 题目大意 有一个长为L的木棍,木棍中间有n个切点.每次切割的费用为当前木棍的长度.求切割木棍的最小费用 输入输出 第一行是木棍的 ...

  8. UVA 10891 区间DP+博弈思想

    很明显带有博弈的味道.让A-B最大,由于双方都采用最佳策略,在博弈中有一个要求时,让一方的值尽量大.而且由于是序列,所以很容易想到状态dp[i][j],表示序列从i到j.结合博弈中的思想,表示初始状态 ...

  9. UVA - 1625 Color Length[序列DP 代价计算技巧]

    UVA - 1625 Color Length   白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束   和模拟赛那道环形DP很想,计算这 ...

随机推荐

  1. 二进制部署Kubernetes-v1.14.1集群

    一.部署Kubernetes集群 1.1 Kubernetes介绍 Kubernetes(K8S)是Google开源的容器集群管理系统,K8S在Docker容器技术的基础之上,大大地提高了容器化部署应 ...

  2. netty百万连接跟踪记录

    0. 启动客户端和服务端 # 测试环境: centos7 jdk8 2核16G# 服务端启动nohup java -Xmx8192m -Xms4096m -XX:+UseG1GC -XX:Parall ...

  3. Springboot 版本+ jdk 版本 + Maven 版本的对应关系

    Spring boot 版本 Spring Framework jdk 版本 maven 版本 1.2.0 版本之前   6 3.0 1.2.0 4.1.3+ 6 3.2+ 1.2.1 4.1.3+ ...

  4. 数据库操作通用函数,增强可重复利用性能C#,asp.net.sql2005

    using System;using System.Data;using System.Data.SqlClient; namespace com.hua..li{ /// <summary&g ...

  5. 5.13会话技术Cookie---Session

    .会话技术: 1.会话:一次会话中包含多次请求和相应. 一次会话:浏览器第一次给服务器资源发送请求,会话建立,直到有一方断开为止 2.功能:在一次会话的范围内的多次请求间,共享数据 3.方式: 1.客 ...

  6. MemcachedClient 使用说明

    上一篇介绍了Memcached基本使用方法<Memcached使用手册>,下面介绍java如何操作memcached.使用的是java_memcached-release_2.6.6. 一 ...

  7. MySql-Connector for NET 连接驱动选择

    尝试在Visual Studio2010, 2012环境下链接Mysql, 为啥不直接在App.config里面写字符串, 当然是可以,但是当你想用EF 的时候,必须要有个数据源, 首先在[服务资源管 ...

  8. https 结合使用 对称加密和非对称加密

    (一)对称加密(Symmetric Cryptography) ---共享密钥加密 对称加密是最快速.最简单的一种加密方式,加密(encryption)与解密(decryption)用的是同样的密钥( ...

  9. 【Oracle】详解ADDM工具

    一.ADDM简介           在Oracle9i及之前,DBA们已经拥有了很多很好用的性能分析工具,比如,tkprof.sql_trace.statspack.set event 10046& ...

  10. 用cmd查看win8版本 激活等详细信息命令

    Win+x===>选择以管理员身份运行,输入: slmgr /dlv   显示:最为详尽的激活信息,包括:激活ID.安装ID.激活截止日期slmgr /dli 显示:操作系统版本.部分产品密钥. ...