Codeforces Gym 100231G Voracious Steve 记忆化搜索
Voracious Steve
题目连接:
http://codeforces.com/gym/100231/attachments
Description
有两个人在玩一个游戏
有一个盆子里面有n个甜甜圈,A先开始,他可以抓[1,min(m,n)]颗甜甜圈,然后B开始,同样,可以抓[1,min(n,m)]个甜甜圈
谁抓完的,就可以把自己抓的吃完,然后另外一个人就把他的甜甜圈扔进去,然后由失败的那个人开始
问你第一个人最多能吃到多少个甜甜圈
Input
2个整数 n,m
表示一开始有n个甜甜圈,一次最多抓m个
Output
输出第一个人最多吃多少个甜甜圈
Sample Input
5 3
Sample Output
2
Hint
题意
题解:
记忆化搜索,dp[n][x][y]表示中间有n个甜甜圈,第一个人有x个,第二个人有y个的最优值
然后一直搜下去就好了
代码
#include<bits/stdc++.h>
using namespace std;
int dp[105][105][105];
int n,m;
int dfs(int n,int x,int y)//还有n个,我身上有x个,他身上有y个我能吃的最大值
{
if(dp[n][x][y]>=0)return dp[n][x][y];
for(int i=1;i<=m&&i<=n;i++)
{
int sp = n+x+y;
if(i==n)sp-=dfs(y,0,0);
else sp-=dfs(n-i,y,x+i);
dp[n][x][y]=max(dp[n][x][y],sp);
}
return dp[n][x][y];
}
int main()
{
memset(dp,-1,sizeof(dp));
scanf("%d%d",&n,&m);
dp[0][0][0]=0;
cout<<dfs(n,0,0)<<endl;
}
Codeforces Gym 100231G Voracious Steve 记忆化搜索的更多相关文章
- Codeforces 900D Unusual Sequences:记忆化搜索
题目链接:http://codeforces.com/problemset/problem/900/D 题意: 给定x,y,问你有多少个数列a满足gcd(a[i]) = x 且 ∑(a[i]) = y ...
- GYM 101933E 状态压缩 + 记忆化搜索
题意:我方有n个士兵,敌方有m个,每方士兵都有一个血量,现在有k轮无差别炮火打击,每次都会从存活的士兵中随机选一人,这名士兵的HP就-1,问对方被团灭的概率有多大? 思路:因为n和m的范围很小,我们可 ...
- Codeforces 1079C Playing Piano(记忆化搜索)
题目链接:Playing Piano 题意:给定长度为n的序列$a_i$,要求得到同样长度的序列$b_i$.满足一下条件: if $a_i < a_{i+1}$ then $b_i < b ...
- Codeforces 251C Number Transformation DP, 记忆化搜索,LCM,广搜
题意及思路:https://blog.csdn.net/bossup/article/details/37076965 代码: #include <bits/stdc++.h> #defi ...
- Codeforces Gym 191033 E. Explosion Exploit (记忆化搜索+状压)
E. Explosion Exploit time limit per test 2.0 s memory limit per test 256 MB input standard input out ...
- CodeForces 173C Spiral Maximum 记忆化搜索 滚动数组优化
Spiral Maximum 题目连接: http://codeforces.com/problemset/problem/173/C Description Let's consider a k × ...
- Codeforces Round #336 (Div. 2) D. Zuma 记忆化搜索
D. Zuma 题目连接: http://www.codeforces.com/contest/608/problem/D Description Genos recently installed t ...
- Educational Codeforces Round 1 E. Chocolate Bar 记忆化搜索
E. Chocolate Bar Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/prob ...
- CodeForces 398B 概率DP 记忆化搜索
题目:http://codeforces.com/contest/398/problem/B 有点似曾相识的感觉,记忆中上次那个跟这个相似的 我是用了 暴力搜索过掉的,今天这个肯定不行了,dp方程想了 ...
随机推荐
- Collectl基础
Collectl比nmon更专业和深入的linux性能测试工具 首先是安装 $ sudo apt-get install collectl 直接输入collectl就可以看到数据 默认是CPU,硬盘, ...
- android命名规范
Android 开发规范 (陈杨) (一)注意事项 1. 编码方式统一用UTF-8. Android Studio默认已是UTF-8,只要不去改动它就可以了. 2. 缩进统一为4个空格,将Tab si ...
- Mac OS10.9 下python开发环境(eclipse)以及自然语言包NLTK的安装与注意
折腾了大半天,终于把mbp上python自然语言开发环境搭建好了. 第一步,安装JDK1.7 for mac MacOS10.9是自带python2.7.5的,够用,具体的可以打开终端输入python ...
- effective c++:资源管理
对象管理资源 createInvestment 函数作用时创建一个invest对象: void f() { Investment *pInv = createInvestment(); // call ...
- RFID之UID
1 Unique identifier (UID) The VICCs are uniquely identified by a 64 bits unique identifier (UID). Th ...
- Controlling GameObjects Using Components
[Accessing Components] The most common case is where a script needs access to other Components attac ...
- spring 的properties解析
一般使用PropertyPlaceholderConfigurer来替换占位符,例如: <bean class="org.springframework.beans.factory.c ...
- LeetCode7:Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to ...
- 安装Sass
最近要开始用 Sass 做一些东西.先来记录一下安装过程. 1.确认本机的 Ruby 版本 2.访问网址下载 Sass 最新版本 https://rubygems.org/gems/sass 3.下载 ...
- SpringMVC+JPA使用注入的方式环境搭建
----------------------------------------------------DAO--------------------------------------------- ...