题意:给你一个数字n,有两种操作:减1或乘2,问最多经过几次操作能变成m;
随后发篇随笔普及下memset函数的初始化问题。自己也是涨了好多姿势。
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#define INF 0x7fffffff;
using namespace std;
int DP[], vis[];
int dp(int n, int m)
{
if(n <= ) return INF;
if(n >= m) {DP[n] = n-m; return DP[n];}
if(!vis[n])
{
vis[n] = ;
//cout << n << "+++" << endl;
DP[n] = min(dp(n-, m), dp(n*, m))+;
}
return DP[n];
}
int main()
{
int n, m;
while(~scanf("%d%d", &n, &m)){
memset(DP, 0x3f3f3f3f, sizeof(DP));
memset(vis, , sizeof(vis));
//cout << DP[0] << endl;
printf("%d\n", dp(n, m));
}
return ;
}
【记忆化搜索】Codeforces Round #295 (Div. 2) B - Two Buttons的更多相关文章
-
Codeforces Round #295 (Div. 2)---B. Two Buttons( bfs步数搜索记忆 )
B. Two Buttons time limit per test : 2 seconds memory limit per test :256 megabytes input :standard ...
-
Codeforces Round #295 (Div. 2)B - Two Buttons BFS
B. Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
-
Codeforces Round #295 (Div. 2) B. Two Buttons
B. Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
-
Codeforces Round #295 (Div. 2) B. Two Buttons 520B
B. Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
-
Codeforces Round #295 (Div. 2) B. Two Buttons (DP)
题意:有两个正整数\(n\)和\(m\),每次操作可以使\(n*=2\)或者\(n-=1\),问最少操作多少次使得\(n=m\). 题解:首先,若\(n\ge m\),直接输出\(n-m\),若\(2 ...
-
Codeforces Round #295 (Div. 2)
水 A. Pangram /* 水题 */ #include <cstdio> #include <iostream> #include <algorithm> # ...
-
codeforces 521a//DNA Alignment// Codeforces Round #295(Div. 1)
题意:如题定义的函数,取最大值的数量有多少? 结论只猜对了一半. 首先,如果只有一个元素结果肯定是1.否则.s串中元素数量分别记为a,t,c,g.设另一个串t中数量为a',t',c',g'.那么,固定 ...
-
Codeforces Round #295 (Div. 2)C - DNA Alignment 数学题
C. DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
-
Codeforces Round #295 (Div. 2)A - Pangram 水题
A. Pangram time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
随机推荐
-
R语言:规划求解优化ROI
今天看到一篇文章介绍如何用excel建模对ROI 进行规划求解. 蓝鲸的网站分析笔记 成本 Cost 每次点击费用 CPC 点击量 \[clickRate = \frac{cost}{CPC}\] 转 ...
-
sicily 1007. To and Fro 2016 11 02
// Problem#: 1007// Submission#: 4893204// The source code is licensed under Creative Commons Attrib ...
-
flash cs6导入某些mp3不能的解决办法
安装最新的quicktime 另外还有一个很恶心的办法,可以不用装quicktime. 1.用adobe audio打开一个没问题的mp3, 2.再打开有问题的MP3,全选,复制: 3.切换到没问题的 ...
-
C中不安全函数
C 中大多数缓冲区溢出问题可以直接追溯到标准 C 库.最有害的罪魁祸首是不进行自变量检查的.有问题的字符串操作(strcpy.strcat.sprintf 和 gets).一般来讲,象“避免使用 st ...
-
MYCAT介绍
为什么需要MyCat? http://www.mycat.org.cn/ http://www.csdn.net/article/2015-07-16/2825228
-
This 关键字和变量作用域
public class Number { int count; public void method01(){ // int count=3; count=3; // t ...
-
HDU 5071 Chat
题意: CLJ找了很多妹子- (题目好没节操-) 对于CLJ和妹子的聊天对话框 有一下几种操作: add 加一个妹子在聊天窗队列末尾 假设这个妹子已经在队列中则add失败 close 关掉 ...
-
node.js学习资料(2015-12)
使用vscode开发,设置代码智能提示的方法,cd 项目目录,然后使用以下命令npm install tsd -gtsd install node express angular -ros 下载 Gi ...
-
huffman(greedy)
present a file by binary character code,let the less characters can be presented simplier. package g ...
-
【BZOJ-3123】森林 主席树 + 启发式合并
3123: [Sdoi2013]森林 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 2738 Solved: 806[Submit][Status] ...