输出1到n中含有6的数的个数。

样例输入

100

样例输出

19

找规律感觉好难想(好像是什么100以内有19个,200以内有19*2个,600以内115个,700以内214个...,1000以内有271,2000以内有2*271个),就直接套数位dp的模板了。

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int dp[][];
int digit[]; int dfs(int pos,int sta,bool limit)
{
if(pos==) return sta==;
if(!limit&&dp[pos][sta]!=-)
return dp[pos][sta];
int ans=;
int up=limit?digit[pos]:;
for(int i=;i<=up;i++){
int nsta=;
if(sta||i==) nsta=;
ans+=dfs(pos-,nsta,limit&&i==up);
}
if(!limit) return dp[pos][sta]=ans;
return ans;
} int solve(int x)
{
int len=;
while(x){
digit[++len]=x%;
x/=;
}
return dfs(len,,true);
} int main()
{
int n;
memset(dp,-,sizeof(dp));
while(scanf("%d",&n)==)
{
printf("%d\n",solve(n));
}
return ;
}

找顺数【数位dp】的更多相关文章

  1. 找规律/数位DP HDOJ 4722 Good Numbers

    题目传送门 /* 找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one () http://www.cnblogs.com/crazyapple/p/3315436.html 数 ...

  2. 2017年icpc西安网络赛 Maximum Flow (找规律+数位dp)

    题目 https://nanti.jisuanke.com/t/17118 题意 有n个点0,1,2...n-1,对于一个点对(i,j)满足i<j,那么连一条边,边权为i xor j,求0到n- ...

  3. Codeforces D. Little Elephant and Interval(思维找规律数位dp)

    题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...

  4. CF809C(找规律+数位DP)

    老年选手需要多写一些思维题qwq. 通过打表很容易发现对于(i,j),值为(i-1)^(j-1)+1,然后本题就没了qwq. 矩阵差分还是很容易想到的,容斥成四个矩阵. 然后看到异或很容易想到三件事: ...

  5. HDU - 4722 Good Numbers 【找规律 or 数位dp模板】

    If we sum up every digit of a number and the result can be exactly divided by 10, we say this number ...

  6. UVALive - 6575 Odd and Even Zeroes 数位dp+找规律

    题目链接: http://acm.hust.edu.cn/vjudge/problem/48419 Odd and Even Zeroes Time Limit: 3000MS 问题描述 In mat ...

  7. HDU 4588 Count The Carries 数位DP || 打表找规律

    2013年南京邀请赛的铜牌题...做的非常是伤心.另外有两个不太好想到的地方.. ..a 能够等于零,另外a到b的累加和比較大.大约在2^70左右. 首先说一下解题思路. 首先统计出每一位的1的个数, ...

  8. 数位DP入门

    HDU 2089 不要62 DESC: 问l, r范围内的没有4和相邻62的数有多少个. #include <stdio.h> #include <string.h> #inc ...

  9. 浅谈数位DP

    在了解数位dp之前,先来看一个问题: 例1.求a~b中不包含49的数的个数. 0 < a.b < 2*10^9 注意到n的数据范围非常大,暴力求解是不可能的,考虑dp,如果直接记录下数字, ...

随机推荐

  1. Jmeter分布式测试笔记

    在性能测试过程中,如果要求并发数较大时(例如1000+),单机配置cpu与内存等无法支持,则需要使用Jmeter的分布式测试方法. 一.一般什么情况下需要分布式 1.前辈经验:比如机器i5双核的cpu ...

  2. Python - 集合与元素之数据类型和变量总结

    变量 变量的作用:保存状态(程序的运行本质是一系列的变化,变量的目的就是用来保存状态,变量值的变化就构成了程序运行的不同结果.) 例如:cs枪战中,一个人的生命可以表示为life = True 表示存 ...

  3. python第四课

    1.lambda()函数 可以直接定义一个函数,简化用def的定义. >>> func=lambda x,y:x+y>>> print(func(3,4))7> ...

  4. OSG能够在当前帧截图,也就是能转换视角后马上截图

    #include <Windows.h> #include <osg/GraphicsContext> #include <osg/Group> #include ...

  5. groups 用户所归属的用户组查询

    groups 用法很简单,就是查询用户所归属哪个或哪些用户组: 语法格式:  groups  用户名 实例: [beinan@localhost ~]$ groups beinan  注:查询bein ...

  6. Leetcode106. Construct Binary Tree from Inorder and Postorder Traversal中序后续构造二叉树

    根据一棵树的中序遍历与后序遍历构造二叉树. 注意: 你可以假设树中没有重复的元素. 例如,给出 中序遍历 inorder = [9,3,15,20,7] 后序遍历 postorder = [9,15, ...

  7. Leetcode532.K-diff Pairs in an Array数组中的K-diff数对

    给定一个整数数组和一个整数 k, 你需要在数组里找到不同的 k-diff 数对.这里将 k-diff 数对定义为一个整数对 (i, j), 其中 i 和 j 都是数组中的数字,且两数之差的绝对值是 k ...

  8. 探索云网络技术前沿,Sigcomm 2019 阿里云参会分享

    Sigcomm 2019简介 一年一度的网络顶级学术峰会Sigcomm于8月20日至22日在北京举行.作为ACM Special Interest Group on Data Communicatio ...

  9. 几个树形dp

    1.重建道路 树形dp基础题,f[i][j]表示在i这个点我和我的子树联通块大小为j最少砍几条边. 转移的时候,到下一个子树时上一个子树所有答案先++(此树直接砍掉不贡献答案),再继续dp. 注意更新 ...

  10. solr问题missing content stream

    在使用solrj建立索引的时候,报错:missing content stream; 原因在于 HttpSolrServer httpSolrServer = new HttpSolrServer(s ...