题意:给你一个数字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 #295 (Div. 2)---B. Two Buttons( bfs步数搜索记忆 )

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

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #295 (Div. 2) B. Two Buttons (DP)

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

  6. Codeforces Round #295 (Div. 2)

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

  7. codeforces 521a//DNA Alignment// Codeforces Round #295(Div. 1)

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

  8. 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 ...

  9. 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 ...

随机推荐

  1. JSF 2 outputText example

    In JSF 2.0 web application, "h:outputText" tag is the most common used tag to display plai ...

  2. oracle 监测数据库是否存在指定字段

    public static bool ExistColumn(string tableName, string columnName, string connStr) { using (OracleC ...

  3. 面试之BI-SQL--table转换

    题目如下: Num 1 2 4 6 7 8 10 11 13 写条SQL语句转成下表: Column1  Column2 1              2 4              4 6     ...

  4. HDU 3966 Aragorn's Story (树链点权剖分,成段修改单点查询)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3966 树链剖分的模版,成段更新单点查询.熟悉线段树的成段更新的话就小case啦. //树链剖分 边权修 ...

  5. poj3083

    Children of the Candy Corn Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8046   Accep ...

  6. IIS6的SSL配置,如何配置SSL到登陆页,如何将SSL证书设置成受信任的证书

    一. 申请证书1. 到受信任的机构申请 略 2. 到自建的证书服务器申请 a. 安装证书服务 通过控制面板中的“添加/删除程序”,选择“添加/删除Windows组件”.在Windows组件向导中找到“ ...

  7. HTTP Post Request using Apache Commons

    Demonstrates an HTTP Post using the Apache Commons HTTP library. Required Libraries: httpcore-4.1.ja ...

  8. Codeforces Round #115 A. Robot Bicorn Attack 暴力

    A. Robot Bicorn Attack Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/17 ...

  9. 使用C# 生成word记录

    private void button1_Click(object sender, System.EventArgs e) { object oMissing = System.Reflection. ...

  10. ApiDemo/FragmentRetainInstance 解析

    /* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache License, Versi ...