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

题意

  求区间${[1,n]}$含有49的数的个数。

Solution

  数位dp,先求出不含49的,再减一下就好了。

细节

  LL

代码

// hdu3555
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>
#define LL long long
#define inf (1ll<<30)
#define MOD 1004535809
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std; LL f[20][10],g[20],m,ans;
int t[20],n; int main() {
int T;scanf("%d",&T);
while (T--) {
scanf("%lld",&m);ans=m;
for (n=0;m;m/=10) t[++n]=m%10;
memset(f,0,sizeof(f));memset(g,0,sizeof(g));
g[1]=1;
for (int i=0;i<10;i++) f[1][i]=1;
for (int i=2;i<=n;i++) {
for (int j=0;j<10;j++)
for (int k=0;k<10;k++)
if (j!=4 || k!=9) f[i][j]+=f[i-1][k];
for (int j=0;j<t[i-1];j++) if (t[i]!=4 || j!=9) g[i]+=f[i-1][j];
if (t[i]!=4 || t[i-1]!=9) g[i]+=g[i-1];
}
for (int i=1;i<n;i++)
for (int j=1;j<10;j++) ans-=f[i][j];
for (int i=1;i<t[n];i++) ans-=f[n][i];
ans-=g[n];
printf("%lld\n",ans);
}
return 0;
}

【hdu3555】 Bomb的更多相关文章

  1. 【Hdu3555】 Bomb(数位DP)

    Description 题意就是找0到N有多少个数中含有49. \(1\leq N \leq2^{63}-1\) Solution 数位DP,与hdu3652类似 \(F[i][state]\)表示位 ...

  2. 【hdu3555】Bomb 数位dp

    题目描述 求 1~N 内包含数位串 “49” 的数的个数. 输入 The first line of input consists of an integer T (1 <= T <= 1 ...

  3. 【CSAPP】Bomb Lab实验笔记

    bomblab这节搞的是二进制拆弹,可以通俗理解为利用反汇编知识找出程序的六个解锁密码. 早就听闻BOMBLAB的大名,再加上我一直觉得反汇编是个很艰难的工作,开工前我做好了打BOSS心理准备.实际上 ...

  4. 【HDOJ】【3555】Bomb

    数位DP cxlove基础数位DP第二题 与上题基本相同(其实除了变成long long以外其实更简单了……) //HDOJ 3555 #include<cmath> #include&l ...

  5. 【HDU5934】Bomb——有向图强连通分量+重建图

    题目大意 二维平面上有 n 个爆炸桶,i−thi-thi−th爆炸桶位置为 (xi,yi)(x_i, y_i)(xi​,yi​) 爆炸范围为 rir_iri​ ,且需要 cic_ici​ 的价格引爆, ...

  6. 【模拟】Codeforces 699B One Bomb

    题目链接: http://codeforces.com/problemset/problem/699/B 题目大意: N*M的图,*代表墙.代表空地.问能否在任意位置(可以是墙上)放一枚炸弹(能炸所在 ...

  7. 【HDU 3555】 Bomb

    [题目链接] 点击打开链接 [算法] 数位DP [代码] #include<bits/stdc++.h> using namespace std; #define MAXL 15 type ...

  8. 【转】2-SAT题集

    转自:http://blog.csdn.net/shahdza/article/details/7779369 [HDU]3062 Party1824 Let's go home3622 Bomb G ...

  9. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

随机推荐

  1. Kafka发送到分区的message是否是负载均衡的?

    首先说结论,是负载均衡的.也就是说,现在有一个producer,向一个主题下面的三个分区发送message,没有指定具体要发送给哪个partition, 这种情况,如果是负载均衡的,发送的消息应该均匀 ...

  2. Python 利用 BeautifulSoup 爬取网站获取新闻流

    0. 引言 介绍下 Python 用 Beautiful Soup 周期性爬取 xxx 网站获取新闻流: 图 1 项目介绍 1. 开发环境 Python: 3.6.3 BeautifulSoup:   ...

  3. .NetCore mvc Ajax Post数据到后端

    在前端页面中,如果没有表单,想把复杂对象提交到后端,可使用以下方法 后端Controller中定义以下方法: [HttpPost] public int AddSolution([FromBody]S ...

  4. 03-matplotlib-折线图

    import numpy as np import matplotlib.pyplot as plt import matplotlib.dates as mdates ''' 折线图,用直线段将各数 ...

  5. LeetCode 404. Sum of Left Leaves (C++)

    题目: Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are t ...

  6. 项目Beta冲刺(团队)第四天

    1.昨天的困难 返回提问者昵称的时候返回信息不全,个别信息没有返回过去 一开始ProgressBar控件的显示有问题 需要实现类似聊天的功能,采用listview承载聊天内容,对于自定义适配器的构建使 ...

  7. TCP 连接管理

    实验代码和内容:https://github.com/ZCplayground/Understanding-Unix-Linux-Programming/tree/master/11.socket 明 ...

  8. jquery-numberformatter插件

    项目地址:https://code.google.com/p/jquery-numberformatter/ 非jquery版:https://github.com/andrewgp/jsNumber ...

  9. angularJS1笔记-(10)-自定义指令(templateUrl属性)

    index.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  10. 自动创建web.xml

    摘自:http://blog.csdn.net/weiral/article/details/51366485 今天在学习JSP时先创建了一个web项目,后来在用到web.xml文件时,才发现项目创建 ...