(数位dp)Bomb (hdu 3555)
Now the counter-terrorist knows the number N. They want to know the final points of the power. Can you help them?
The input terminates by end of file marker.
1
50
500
1
15
From 1 to 500, the numbers that include the sub-sequence "49" are "49","149","249","349","449","490","491","492","493","494","495","496","497","498","499",
so the answer is 15.
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long LL; LL dp[][];
/**
* dp[i][0],表示长度为i,不存在不吉利数字
* dp[i][1],表示长度为i, 不存在不吉利数字,且最高位为9
* dp[i][2],表示长度为i, 存在不吉利数字
*/ void Init()
{
int i; dp[][] = ;
for(i=; i<; i++)
{
dp[i][] = *dp[i-][] - dp[i-][];
dp[i][] = dp[i-][];
dp[i][] = *dp[i-][] + dp[i-][];
}
} LL Slove(LL n)
{
int i, a[]={}, len=, flag=;
LL n1 = n, ans=; while(n1)
{
a[++len] = n1%;
n1 /= ;
} for(i=len; i>=; i--)
{
ans += dp[i-][]*a[i];
if(flag)///高位已经出现49了,后面随意
ans += dp[i-][]*a[i];
else if(!flag && a[i]>)
ans += dp[i-][];
if(a[i+]== && a[i]==)
flag = ;
} return ans;
}
int main()
{
int T;
Init();
scanf("%d", &T);
while(T--)
{
LL n; scanf("%I64d", &n); printf("%I64d\n", Slove(n+));
}
return ;
}
(数位dp)Bomb (hdu 3555)的更多相关文章
- Bomb HDU - 3555 (数位DP)
Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...
- Bomb HDU - 3555
Bomb HDU - 3555 求1~n中含有49数的个数 #include<bits/stdc++.h> #define LL long long using namespace std ...
- Bomb HDU 3555 dp状态转移
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题意: 给出一个正整数N,求出1~N中含有数字“49”的数的个数 思路: 采用数位dp的状态转移方程 ...
- 数位dp入门 HDU 2089 HDU 3555
最基本的一类数位dp题,题目大意一般是在a~b的范围,满足某些要求的数字有多少个,而这些要求一般都是要包含或者不包含某些数字,或者一些带着数字性质的要求,一般来说暴力是可以解决这一类问题,可是当范围非 ...
- 【数位DP】Hdu 2089:不要62
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 数位DP入门(A - 不要62 HDU - 2089 &&B - Bomb HDU - 3555 )
题目链接:https://cn.vjudge.net/contest/278036#problem/A 具体思路:对于给定的数,我们按照位数进行运算,枚举每一位上可能的数,在枚举的时候需要注意几个条件 ...
- Bomb HDU - 3555 数位dp
Code: #include<cstdio> #include<algorithm> #include<cstring> #include<string> ...
- 【数位DP】 HDU 4734 F(x)
原题直通车:HDU 4734 F(x) 题意:F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1, 求0.....B中F[x]<=F[A ...
- 【数位DP】Hdu 3652:B-number
B-number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 【数位DP】 HDU 4722 Good Numbers
原题直通车: HDU 4722 Good Numbers 题意: 求区间[a,b]中各位数和mod 10==0的个数. 代码: #include<iostream> #include& ...
随机推荐
- threejs 世界坐标转化为屏幕坐标
网站: http://www.yanhuangxueyuan.com/Three.js_course/screen.html 方法.project 通过Vector3对象的方法project,方法的参 ...
- ES6解构赋值的应用场景
一.变量交换 1.ES6的方式 { let a=; let b=; [a,b]=[b,a]; console.log(a,b); } 输出为 2.ES5的方式 采用中间变量的方式进行存储 二.获取函数 ...
- 10. pt-fk-error-logger
pt-fk-error-logger DSN 外键约束相关的,不关注.
- jQuery操作(一)
基本语法:$(selector).action() 寻找元素(重要的选择器和筛选器) 一:选择器 1.1 基本选择器: $("*") $("#id") $(&q ...
- 判断\r\n结束标准
ucPrev==0x0D&&ucCur==0x0A \r\n uint8_t ucPrev =0,ucCur = 0; uint32_t recvlen = 0; for (; uiL ...
- Spring 属性注入(三)AbstractNestablePropertyAccessor
Spring 属性注入(三)AbstractNestablePropertyAccessor Spring 系列目录(https://www.cnblogs.com/binarylei/p/10117 ...
- ubuntu下安装maven(转载)
下载maven http://maven.apache.org/download.cgi 解压 tar -xzvf apache-maven-3.0.5-bin.tar.gz 配置环境变量 sudo ...
- Apache Prefork、Worker和Event三种MPM分析
三种MPM介绍 Apache 2.X 支持插入式并行处理模块,称为多路处理模块(MPM).在编译apache时必须选择也只能选择一个MPM,对类UNIX系统,有几个不同的MPM可供选择,它们会影响到 ...
- linux_修改ip(重启后永久生效)
vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet UUID=a20869f2-4095-4e5d-9b0c- ...
- 【转】Centos yum 换源
[1] 首先备份/etc/yum.repos.d/CentOS-Base.repo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/Cent ...