<传送门>

B - Apple

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)
SubmitStatus

Problem Description

Alice and Bob are coming.
This time, they are playing with apples. Initially, there are N baskets and M apples. Both baskets and apples are distinguishable. Each turn, (s)he can choose adding a basket or an apple. Alice always plays first. When (s)he complete operation, if the number of ways to split apples into baskets is not less than A, (s)he lose.
Now Alice wonder whether she can win if both player use best strategy.

Input

There are multiple test cases.
Each test case contains three integers N, M and A.
1 <= N <= 10,000
1 <= M <= 30
2 <= A <= 1,000,000,000

Output

For each test case, if Alice can win, output "win" and if Bob can win, output "lose"; otherwise output "draw".

Sample Input

3 1 4
2 2 10

Sample Output

lose
win

【题目大意】

有N个篮子和M个苹果,篮子和苹果都是有区别的。
对于每一个回合,他或她可以选择增加一个篮子或者一个苹果。爱丽丝总是第一个动手。
当他们完成一次操作后,如果将苹果分配到篮子里的方法大于等于A,则输。

现在要你判断先手的胜负。

N----篮子数
M---苹果数
A---上限

【题目分析】

定位:常见的dp博弈 、记忆化搜索

像这种没有SG函数的博弈已经很少见了,SG函数的博弈才真叫人蛋疼。

这题的一个细节的地方就是当篮子数=1的时候判断有点麻烦,其他的也不是很难。

具体看代码(注释很详细):

//Memory   Time
// 1680K 0MS
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<iomanip>
#include<string>
#include<climits>
#include<cmath>
#define MAX 1100
#define LL long long
using namespace std;
int dp[40][30];
int A;
bool check(int n,int m){ //组合数
long long way=1;
for(int i=1;i<=n;i++){
way*=m;
if(way>=A) //不满足条件
return false;
}
return true; //满足条件
} //2--- 平局
//1-----win
//0----lose int dfs(int n,int m){
if(m==1){ //这个是细节,开始一直没想到
if(n*n>=A){
return 2; //只有一个篮子,并且一开始就大于A,平局
}
else{
int tmp1=-1,tmp2=-1;
if(check(n+1,m)){
tmp1=dfs(n+1,m);
if(tmp1==0) return 1;
}
if(check(n,m+1)){
tmp2=dfs(n,m+1);
if(tmp2==0)return 1;
}
if(tmp1==2) return 2;
else return 0;
}
} //使用dp数组来记录每一次的搜索值(记忆化搜索) if(dp[n][m]!=-1)
return dp[n][m];
int tmp1=-1,tmp2=-1;
if(check(n+1,m)){
tmp1=dfs(n+1,m);
if(tmp1==0) return dp[n][m]=1;
}
if(check(n,m+1)){
tmp2=dfs(n,m+1);
if(tmp2==0) return dp[n][m]=1;
}
if(tmp1==2||tmp2==2) return dp[n][m]=2;
else return dp[n][m]=0;
} int main(){
// freopen("cin.txt","r",stdin);
// freopen("cout.txt","w",stdout);
int n,m;
while(scanf("%d %d %d",&m,&n,&A)!=EOF){
memset(dp,-1,sizeof(dp));
int k=dfs(n,m);
if(k==2)puts("draw");
else if(k==1)puts("win");
else puts("lose");
}
return 0;
}

  

dp --- acdream原创群赛(16) --- B - Apple的更多相关文章

  1. ACdream原创群赛__15

    这场感觉题目确实还算可以,不过,说好的每题10s效果上却不理想.这个时限还算比较紧.因为时间不是按绝对的多出几秒来计算,而是几倍来计算的. 比赛做的不好,后面又去做了一下. A:典型的数位DP,一直坑 ...

  2. ACdream原创群赛(13)のwuyiqi退役专场 C True love

    True love Time Limit: 4000/2000 MS (Java/Others)     Memory Limit:128000/64000 KB (Java/Others) Prob ...

  3. ACdream原创群赛(18)のAK's dream题解

    只做了4题水题ADGI A题需要注意的就是“[...]”的输出了,何时输出,何时不输出. #include <stdio.h> int main() { int n, cur, d; ; ...

  4. 群赛 ZOJ3741(dp) ZOJ3911(线段树)

    zoj3741 简单dp.wa了两个小时,中间改了好多细节.后来还是不对,参考了别人的代码,发现一个致命问题,初始化的时候,不是每种状态都能直接达到的.初始化成-1. (题目有个小坑,0<=L& ...

  5. ACdream群赛1112(Alice and Bob)

    题意:http://acdream.info/problem?pid=1112 Problem Description Here  is Alice and Bob again ! Alice and ...

  6. centos环境 使用kubeadm快速安装k8s集群v1.16.2

    全程使用root用户运行,宿主机需要连接外网 浏览一下官方kubeadm[有些镜像用不了] https://kubernetes.io/docs/setup/production-environmen ...

  7. [原创]obj-c编程16:键值编码(KVC)

    原文链接:obj-c编程16:键值编码(KVC) 我们可以借助obj-c中的键值编码(以后简称KVC,Key-Value Coding)来存取类的属性,通过指定所要访问的属性名字符串标示符,可以使用存 ...

  8. 二进制安装K8S集群V1.16.3

    centos linux7.5 cat > /etc/hosts << EOF 192.168.199.221 master 192.168.199.222 node1 192.16 ...

  9. kubeadm部署K8S集群v1.16.3

    本次先更新kubeadm快速安装K8S,二进制安装上次没写文档,后续更新,此次最新的版本是V1.16.3 1.关闭防火墙.关闭selinux.关闭swapoff -a systemctl stop f ...

随机推荐

  1. Xamarin.Forms之页面及导航

    参考链接: Xamarin. Forms 页面 Xamarin.Forms 导航 Xamarin.Forms 第04局:页面 Xamarin.Forms页面代表跨平台的移动应用程序屏幕. 下文描述的所 ...

  2. .Net 下基于Redlock redis 分布式锁实现

    Redlock-cs (C#/.NET implementation). RedLock.net (C#/.NET implementation). Includes async and lock e ...

  3. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  4. python 项目实战之装饰器

    import logging def use_logging(func): def writelog(*args, **kwargs): logging.warning("%s is run ...

  5. cloudstack 安装 install for ubuntu

    准备工作环境信息 修改dns配置 设置阿里源root@sh-saas-cs-manager-online-01:~# mv /etc/apt/sources.list /etc/apt/sources ...

  6. ChIP-seq | ATAC-seq | 数据分析流程

    思来想去,还是觉得ENCODE的流程靠谱,所以又花了快一周来调试,终于排除万难,跑成功了.[2019年12月08日] 以下是ATAC生成的结果目录: call-align call-call_peak ...

  7. 源码编译Redis Desktop Manager ---(转载)

    精美文章转载: 版权声明:本文作者为「Kany.Wang」,本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议.转载请注明出处!原文链接:https://kany.me/20 ...

  8. Debian 9安装java与设置环境变量

    安装默认JRE / JDK 先更新软件包索引: apt update 检查是否已安装Java: java -version 如果当前未安装Java,您将看到以下输出: Output-bash: jav ...

  9. easyui的datagrid的使用记录

    datagrid是在 table的基础上变化而来的, 而不是在div的基础上来的. 从div来变成 datagrid,样式的设置还是是比较麻烦的. dg=datagrid 的标题 来源于 column ...

  10. yum安装python3.6的方法

    # centos7 # 换成阿里云的yum源 yum -y install epel-release yum repolist yum -y install python36 测试 [root@loc ...