(数位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& ...
随机推荐
- VS2010,VS2012,VS2013中,无法嵌入互操作类型“……”,请改用适用的接口的解决方法
在VS2013开发环境下,C#引用COM组件遇到的两个问题: 一开始是COM组件没有注册导致代码引用报错,那么我就使用管理员的命令行方式下,入册COM组件: C:\WINDOWS\system32&g ...
- ES6 Generator的应用场景
一.基础知识 API文档 ES6 诞生以前,异步编程的方法,大概有下面四种. 回调函数 事件监听 发布/订阅 Promise 对象 Generator 函数将 JavaScript 异步编程带入了一个 ...
- CH6901 骑士放置
原题链接 和棋盘覆盖(题解)差不多.. 同样对格子染色,显然日字的对角格子是不同色,直接在对应节点连边,然后就是二分图最大独立集问题. #include<cstdio> #include& ...
- Windows MySQL5.7安装和配置
http://www.leixuesong.cn/category/mysql MySQL5.7是MySQL是最新的MySQL大版本,也是官方认为目前性能最好的.MySQL5.7也有很多改动,很多新的 ...
- MySQL学习笔记-事务相关话题
事务机制 事务(Transaction)是数据库区别于文件系统的重要特性之一.事务会把数据库从一种一致状态转换为另一个种一致状态.在数据库提交工作时,可以确保其要么所有修改都已经保存了,要么所有修改都 ...
- MySQL中的联结表
使用联结能够实现用一条SELECT语句检索出存储在多个表中的数据.联结是一种机制,用来在一条SELECT语句中关联表,不是物理实体,其在实际的数据库表中并不存在,DBMS会根据需要建立联结,且会在查询 ...
- PHP ini 配置无效的坑给自己记录
装redis 扩展时,发现装成功之后扩展一直加载不上, 于是phpinfo 发现Configuration File (php.ini) Path:none Loaded Configuration ...
- Quartz入门教程
public class App { public static void main(String[] args) throws MessagingException, IOException { / ...
- Activiti5 添加/查询审批批注(审批意见)
Activiti5 添加/查询审批批注 Activiti 工作流开发,23张表中,act_hi_commit 中,用于保存流程审核的批注信息: 调用: taskServer.addComment ...
- java 中jar的使用
????????????这里不会 需要学习