【记忆化搜索】Codeforces Round #295 (Div. 2) B - Two Buttons

时间:2022-10-02 08:18:44

题意:给你一个数字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的更多相关文章

  1. Codeforces Round &num;295 &lpar;Div&period; 2&rpar;---B&period; Two Buttons( bfs步数搜索记忆 )

    B. Two Buttons time limit per test : 2 seconds memory limit per test :256 megabytes input :standard ...

  2. Codeforces Round &num;295 &lpar;Div&period; 2&rpar;B - Two Buttons BFS

    B. Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  3. Codeforces Round &num;295 &lpar;Div&period; 2&rpar; B&period; Two Buttons

    B. Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. Codeforces Round &num;295 &lpar;Div&period; 2&rpar; B&period; Two Buttons 520B

    B. Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  5. Codeforces Round &num;295 &lpar;Div&period; 2&rpar; B&period; Two Buttons &lpar;DP&rpar;

    题意:有两个正整数\(n\)和\(m\),每次操作可以使\(n*=2\)或者\(n-=1\),问最少操作多少次使得\(n=m\). 题解:首先,若\(n\ge m\),直接输出\(n-m\),若\(2 ...

  6. Codeforces Round &num;295 &lpar;Div&period; 2&rpar;

    水 A. Pangram /* 水题 */ #include <cstdio> #include <iostream> #include <algorithm> # ...

  7. codeforces 521a&sol;&sol;DNA Alignment&sol;&sol; Codeforces Round &num;295&lpar;Div&period; 1&rpar;

    题意:如题定义的函数,取最大值的数量有多少? 结论只猜对了一半. 首先,如果只有一个元素结果肯定是1.否则.s串中元素数量分别记为a,t,c,g.设另一个串t中数量为a',t',c',g'.那么,固定 ...

  8. Codeforces Round &num;295 &lpar;Div&period; 2&rpar;C - DNA Alignment 数学题

    C. DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  9. Codeforces Round &num;295 &lpar;Div&period; 2&rpar;A - Pangram 水题

    A. Pangram time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

随机推荐

  1. R语言:规划求解优化ROI

    今天看到一篇文章介绍如何用excel建模对ROI 进行规划求解. 蓝鲸的网站分析笔记 成本 Cost 每次点击费用 CPC 点击量 \[clickRate = \frac{cost}{CPC}\] 转 ...

  2. sicily 1007&period; To and Fro 2016 11 02

    // Problem#: 1007// Submission#: 4893204// The source code is licensed under Creative Commons Attrib ...

  3. flash cs6导入某些mp3不能的解决办法

    安装最新的quicktime 另外还有一个很恶心的办法,可以不用装quicktime. 1.用adobe audio打开一个没问题的mp3, 2.再打开有问题的MP3,全选,复制: 3.切换到没问题的 ...

  4. C中不安全函数

    C 中大多数缓冲区溢出问题可以直接追溯到标准 C 库.最有害的罪魁祸首是不进行自变量检查的.有问题的字符串操作(strcpy.strcat.sprintf 和 gets).一般来讲,象“避免使用 st ...

  5. MYCAT介绍

    为什么需要MyCat? http://www.mycat.org.cn/ http://www.csdn.net/article/2015-07-16/2825228

  6. This 关键字和变量作用域

    public class Number {     int count; public void method01(){ //    int count=3;     count=3; //    t ...

  7. HDU 5071 Chat

    题意: CLJ找了很多妹子-  (题目好没节操-)  对于CLJ和妹子的聊天对话框  有一下几种操作: add  加一个妹子在聊天窗队列末尾  假设这个妹子已经在队列中则add失败 close  关掉 ...

  8. node&period;js学习资料&lpar;2015-12&rpar;

    使用vscode开发,设置代码智能提示的方法,cd 项目目录,然后使用以下命令npm install tsd -gtsd install node express angular -ros 下载 Gi ...

  9. huffman&lpar;greedy&rpar;

    present a file by binary character code,let the less characters can be presented simplier. package g ...

  10. 【BZOJ-3123】森林 主席树 &plus; 启发式合并

    3123: [Sdoi2013]森林 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 2738  Solved: 806[Submit][Status] ...