题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555

思路分析:该问题要求求解1—N中的数中含有49的数的个数,可以使用DFA来递推dp公式;详细解释点击链接查看;

代码如下:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std; const int MAX_N = + ;
long long dp[MAX_N][];
int digit[MAX_N]; int NextState(int cur_state, int next_char)
{
if (cur_state == )
{
if (next_char == )
cur_state++;
}
else if (cur_state == )
{
if (next_char == )
++cur_state;
else if (next_char != )
--cur_state;
}
return cur_state;
} int main()
{
int case_times;
long long n; scanf("%d", &case_times);
while (case_times--)
{
int cur_state = , count = ;
int len = ;
long long ans = , temp_value = ; scanf("%I64d", &n);
temp_value = ++n;
while (temp_value)
{
digit[++len] = temp_value % ;
temp_value /= ;
} for (int i = len; i >= ; -- i)
{
++count;
for (int j = ; j < digit[i]; ++ j)
{
memset(dp, , sizeof(dp));
dp[count][NextState(cur_state, j)] = ;
for (int k = count + ; k <= len; ++ k)
{
dp[k][] = * dp[k-][] + * dp[k-][];
dp[k][] = dp[k-][] + dp[k-][];
dp[k][] = dp[k-][] + * dp[k-][];
}
ans += dp[len][];
}
cur_state = NextState(cur_state, digit[i]);
}
printf("%I64d\n", ans);
}
return ;
}

hdoj 3555 Bomb(DFA+dp)的更多相关文章

  1. hdoj 3555 BOMB(数位dp)

    //hdoj 3555 //2013-06-27-16.53 #include <stdio.h> #include <string.h> __int64 dp[21][3], ...

  2. HDU 3555 Bomb 数位dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Mem ...

  3. HDOJ 3555 Bomb

    数位DP的DFS写法.... Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Oth ...

  4. hud 3555 Bomb 数位dp

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Subm ...

  5. HDU - 3555 - Bomb(数位DP)

    链接: https://vjudge.net/problem/HDU-3555 题意: The counter-terrorists found a time bomb in the dust. Bu ...

  6. HDU 3555 Bomb 数位DP 入门

    给出n,问所有[0,n]区间内的数中,不含有49的数的个数 数位dp,记忆化搜索 dfs(int pos,bool pre,bool flag,bool e) pos:当前要枚举的位置 pre:当前要 ...

  7. Bomb HDU - 3555 (数位DP)

    Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...

  8. 数位DP入门之hdu 3555 Bomb

    hdu 3555 Bomb 题意: 在1~N(1<=N<=2^63-1)范围内找出含有 ‘49’的数的个数: 与hdu 2089 不要62的区别:2089是找不不含 '4'和 '62'的区 ...

  9. HDU(3555),数位DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others ...

随机推荐

  1. oracle默认的hr用户使用脚本安装

    1 解压到%ORACLE_HOME%/demo/schema/human_resources/目录下 2 在sys或system用户下运行hr_main.sql脚本(运行命令:@%ORACLE_HOM ...

  2. 浅谈Spring(四)

    一.Spring+MyBatis整合 spring大大简化了Mybatis的开发步骤. 1.MyBatis的开发要点: mybatis-config.xml配置文件:配置与数据库的链接.mapper文 ...

  3. IIS发布网站:CS0016: 未能写入输出文件的解决方法

    “/”应用程序中的服务器错误.-------------------------------------------------------------------------------- 编译错误 ...

  4. Android ActionBar详解(一)--->显示和隐藏ActionBar

    MainActivity如下: package cc.testsimpleactionbar0; import android.os.Bundle; import android.view.View; ...

  5. 基于jQuery带标题的图片3D切换焦点图

    今天给大家分享一款基于jQuery带标题的图片3D切换焦点图.这款焦点图适用浏览器:IE8.360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之窗. 实现的代码. htm ...

  6. IISExpress实现外部访问

    首先修改IISExpress配置文件 \IISExpress\config\applicationhost.config 在website中添加一个binding <binding protoc ...

  7. Java泛型的一点用法(转)

    1.一个优秀的泛型,建议不要这样写public static <K, V> Map<K, V> getMap(String source, String firstSplit, ...

  8. [ javascript ] 司徒正美的fadeOut-fadeIn效果!

    首先感谢司徒正美的文章! 在司徒大神的博客看到一个简单的渐入渐出的效果.全然採用js实现. 例如以下: <!doctype html> <html dir="ltr&quo ...

  9. 编译ycm库

    在安装完YCM之后,重新打开vim还会出现如下的报错信息:ycm_client_support.[so|pyd|dll] and ycm_core.[so|pyd|dll] not detected; ...

  10. 关于js封装框架类库之DOM操作模块(一)

    在前端开发的过程中,javascript极为重要的一个功能就是对DOM对象的操作,而对其封装就是为了更好地进行DOM操作,提高浏览器的支持效率 现在给出一个案例:页面创建三个div,然后给其添加样式 ...