UVa 12525 Boxes and Stones (dp 博弈)

177 篇文章 0 订阅
4 篇文章 0 订阅

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.

\epsfbox{p12525.eps}

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 (1$ \le$S$ \le$200) and B(2$ \le$B$ \le$100), 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


题目链接: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]); 
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
4S店客户管理小程序-毕业设计,基于微信小程序+SSM+MySql开发,源码+数据库+论文答辩+毕业论文+视频演示 社会的发展和科学技术的进步,互联网技术越来越受欢迎。手机也逐渐受到广大人民群众的喜爱,也逐渐进入了每个用户的使用。手机具有便利性,速度快,效率高,成本低等优点。 因此,构建符合自己要求的操作系统是非常有意义的。 本文从管理员、用户的功能要求出发,4S店客户管理系统中的功能模块主要是实现管理员服务端;首页、个人中心、用户管理、门店管理、车展管理、汽车品牌管理、新闻头条管理、预约试驾管理、我的收藏管理、系统管理,用户客户端:首页、车展、新闻头条、我的。门店客户端:首页、车展、新闻头条、我的经过认真细致的研究,精心准备和规划,最后测试成功,系统可以正常使用。分析功能调整与4S店客户管理系统实现的实际需求相结合,讨论了微信开发者技术与后台结合java语言和MySQL数据库开发4S店客户管理系统的使用。 关键字:4S店客户管理系统小程序 微信开发者 Java技术 MySQL数据库 软件的功能: 1、开发实现4S店客户管理系统的整个系统程序; 2、管理员服务端;首页、个人中心、用户管理、门店管理、车展管理、汽车品牌管理、新闻头条管理、预约试驾管理、我的收藏管理、系统管理等。 3、用户客户端:首页、车展、新闻头条、我的 4、门店客户端:首页、车展、新闻头条、我的等相应操作; 5、基础数据管理:实现系统基本信息的添加、修改及删除等操作,并且根据需求进行交流信息的查看及回复相应操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值