dp --- acdream原创群赛(16) --- B - Apple
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.
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
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的时候判断有点麻烦,其他的也不是很难。
具体看代码(注释很详细):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | //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; } |
作者:北岛知寒
出处:https://www.cnblogs.com/crazyacking/p/3839661.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?