为了搞SCOI的几道题先做水数位。
之前听过课,半懂不懂吧,现在清楚了些。 这类题一般满足区间减法,即只需要我们求出(1,n)即可,然后打表也是为了sovle(DataType)服务。
先想好怎么计算,再去想怎么打表。
计算是一般存在这样的问题,就是比如n=abcdef,当a=6时,6开头的不能全算,那就只能先算1~5,然后理解为把6摆好,算下一位,这样我们发现,这个函数是没有包含n这个数的,所以调用是要调用sovle(n+1)

不要62

Problem Description
杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer)。
杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。
不吉利的数字为所有含有4或62的号码。例如:
62315
73418
88914
都属于不吉利号码。但是,61152虽然含有6和2,但不是62连号,所以不属于不吉利数字之列。
你的任务是,对于每次给出的一个牌照区间号,推断出交管局今次又要实际上给多少辆新的士车上牌照了。
 
Input
输入的都是整数对n、m(0<n≤m<1000000),如果遇到都是0的整数对,则输入结束。
 
Output
对于每个整数对,输出一个不含有不吉利数字的统计个数,该数值占一行位置。
 
Sample Input
1 100
0 0
 
Sample Output
80
 
 
 
 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std; int dp[][];//dp[i]表示第i位,dp[i][0]吉利的,dp[i][1]第一位为2的吉利的,dp[i][2]为不吉利的
void table_maker() {
dp[][]=;
for(int i=;i<=;i++){
dp[i][]=dp[i-][]*-dp[i-][];
dp[i][]=dp[i-][];
dp[i][]=dp[i-][]*+dp[i-][]+dp[i-][];
}
}
int calc(int n) {
int a[]={},ans=,flag=,tmp=n*,len=;
for(;tmp/=;)a[++len]=tmp%;
for(int i=len;i>=;i--){
ans+=a[i]*dp[i-][];
if(flag)ans+=a[i]*dp[i-][];
else{
if(a[i]>)ans+=dp[i-][];
if(a[i]>)ans+=dp[i-][];
if(a[i+]==&&a[i]>)ans+=dp[i][];
if(a[i]==||(a[i+]==&&a[i]==))flag=;
}
}
return n-ans;
} int main() {
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout); table_maker();
for(int l,r;~scanf("%d%d",&l,&r)&&(l||r);)printf("%d\n",calc(r+)-calc(l));
return ;
}
 

Bomb(要49)

Problem Description
The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence includes the sub-sequence "49", the power of the blast would add one point.
Now the
counter-terrorist knows the number N. They want to know the final points of the
power. Can you help them?
 
Input
The first line of input consists of an integer T (1
<= T <= 10000), indicating the number of test cases. For each test case,
there will be an integer N (1 <= N <= 2^63-1) as the
description.

The input terminates by end of file marker.

 
Output
For each test case, output an integer indicating the
final points of the power.
 
Sample Input
3
1
50
500
 
Sample Output
0
1
15

Hint

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<cstring>
#include<cstdlib>
#include<algorithm>
#include<stdio.h>
using namespace std;
#ifndef UNIX
#define LL "%I64d"
#else
#define LL "%lld"
#endif
const int N=;
typedef long long ll;
ll dp[N][],x;// dp[][0]不含49 dp[][1]不含49首位为9,dp[][2]含49
void mk_tb() {
dp[][]=;
for(int i=; i<N; i++) {
dp[i][]=dp[i-][]*-dp[i-][];
dp[i][]=dp[i-][];
dp[i][]=dp[i-][]*+dp[i-][];
}
}
ll f(ll n) {
ll tmp=n,ans=;
int a[N]={},flag=;
for(*a=; tmp; tmp/=)a[++*a]=tmp%;
for(int i=*a; i; i--) {
ans+=a[i]*dp[i-][];
if(flag)ans+=a[i]*dp[i-][];
else {
if(a[i]>)ans+=dp[i-][];
if(a[i+]== && a[i]==)flag=;
}
}
return ans;
}
int main() {
freopen("in.txt","r",stdin);
freopen("","w",stdout);
mk_tb();int n;
for(scanf("%d",&n);n--;){
scanf(LL,&x);
printf(LL"\n",f(x+));
} return ;
}

1026: [SCOI2009]windy数

Time Limit: 1 Sec  Memory Limit: 162 MB
Submit: 3075  Solved: 1376
[Submit][Status]

Description

windy定义了一种windy数。不含前导零且相邻两个数字之差至少为2的正整数被称为windy数。 windy想知道,在A和B之间,包括A和B,总共有多少个windy数?

Input

包含两个整数,A B。

Output

一个整数。

Sample Input

【输入样例一】
1 10
【输入样例二】
25 50

Sample Output

【输出样例一】
9
【输出样例二】
20

HINT

【数据规模和约定】

100%的数据,满足 1 <= A <= B <= 2000000000 。

 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cstdio>
#include<numeric>
using namespace std;
typedef int ll;
const int N=;
ll dp[N+][];//dp[i][j]表示第i位为j的windy数的个数
void mk_tb(){
for(int i=;i<=;i++)dp[][i]=;
for(int i=;i<=N;i++){
for(int j=;j<=;j++){
for(int k=;k<=;k++){
if(abs(j-k)>=){
dp[i][j]+=dp[i-][k];
}
}
}
}
}
ll f(ll n){
int ans=,a[N+]={},len=;
for(int tmp=n;tmp;tmp/=)a[++len]=tmp%;
for(int i=;i<len;i++)ans+=accumulate(dp[i]+,dp[i]+N,);
for(int i=;i<a[len];i++)ans+=dp[len][i];
for(int i=len;--i;){
for(int j=;j<a[i];j++)if(abs(j-a[i+])>=)ans+=dp[i][j];
if(abs(a[i]-a[i+])<)break;
}
return ans;
}
int main() {
freopen("in.txt","r",stdin);
freopen("","w",stdout); mk_tb();
int a,b;
scanf("%d%d",&a,&b);
printf("%d\n",f(b+)-f(a)); return ;
}
 

数位DP初步 bzoj1026 hdu2089 hdu3555的更多相关文章

  1. 数位dp浅谈(hdu3555)

    数位dp简介: 数位dp常用于求区间内某些特殊(常关于数字各个数位上的值)数字(比如要求数字含62,49): 常用解法: 数位dp常用记忆化搜索或递推来实现: 由于记忆化搜索比较好写再加上博主比较蒟, ...

  2. 【数位DP】【HDU2089】不要62

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  3. 数位dp初步——数位dp的两种方式

    数位dp:一类统计区间[L,R]内某种符合规定的数字个数的题目.特征是R的范围会很大,O(N)范围内无法完成. 一般而言,解决这类题目有两种方式,一种是递推,另一种是记忆化搜索. 递推: 1)利用dp ...

  4. 数位DP入门题——[hdu2089]不要62

    数位DP是我的噩梦. 现在初三了,却没AC过数位DP的题目. 感觉数位DP都是毒瘤-- 题目 hdu不用登录也可以进去,所以就不把题目copy到这里来了. 题目大意 求区间[n,m][n,m][n,m ...

  5. 数位dp进阶(hdu2089,3652)

    之前的文章已经讲过如何求1—r中的特殊数,这篇博客就来讲些进阶操作: 直接看例题(hdu2089): (题目是中文的我就不写大意了) 这题与hdu3555最大的区别就是规定了l,不再以1开始: 解决这 ...

  6. 【数位DP】bzoj1026: [SCOI2009]windy数

    1026: [SCOI2009]windy数 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 4163  Solved: 1864[Submit][Sta ...

  7. HDU - 2089 数位DP 初步

    中文题目,不要62和4 从高位往低位DP,注意有界标志limit的传递 dp2记忆有界情况下的计数结果,据说用处不大 我所参考的入门文章就是半搜索(有界)半记忆(无界)的 进阶指南中提出dfs维度有多 ...

  8. [BZOJ1026][SCOI2009]windy数 解题报告|数位dp

    Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B之间,包括A和B,总共有多少个windy数? 一直 ...

  9. HDU2089 不要62[数位DP]

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

随机推荐

  1. javascript--15条规则解析JavaScript对象布局(__proto__、prototype、constructor)

    大家都说JavaScript的属性多,记不过来,各种结构复杂不易了解.确实JS是一门入门快提高难的语言,但是也有其他办法可以辅助记忆.下面就来讨论一下JS的一大难点-对象布局,究竟设计JS这门语言的人 ...

  2. javascript——操作符(~、&、|、^、<<、>>)

    直接上代码吧! <script type="text/javascript"> //javascript操作符 //1.按位非~ var num1=25;// var ...

  3. java获取数据库数据表的元数据

    Connction conn; DatabaseMetaData dmd=conn.getMetaData();//获取数据库元数据 PreparedStatment ps; ps.getParame ...

  4. js submit的問題

    form 里面有input name="submit"的时候 $('#seachform').submit();不起作用

  5. PHP 用户注册与登录

    网站用户注册与登录是很常用的一个功能,本节教材就以此来演示一下 PHP 中如何开发用户注册与登录模块. 本节需要用到的重点 PHP 基础知识: PHP 中预定义 $_POST 和 $_GET 全局变量 ...

  6. OC之JSON数据解析

    JSON介绍: 作为一种轻量级的数据交换格式,正在逐步取代XML,成为网络数据的通用格式 基于JavaScript的一个子集 易读性略差,编码手写难度大,数据量小 JSON格式取代了XML给网络传输带 ...

  7. [Winfrom] 捕获窗体最大化、最小化和关闭按钮的事件

    const int WM_SYSCOMMAND = 0x112;const int SC_CLOSE = 0xF060;const int SC_MINIMIZE = 0xF020;const int ...

  8. SQL 测试

    1.SQL 指的是? 您的回答:Structured Query Language 2.哪个 SQL 语句用于从数据库中提取数据? 您的回答:SELECT 3.哪条 SQL 语句用于更新数据库中的数据 ...

  9. CSS HACK的方法

    所有浏览器 通用 height: 100px; IE6 专用 _height: 100px; IE7 专用 *+height: 100px; IE6.IE7 共用 *height: 100px; IE ...

  10. The top 100 papers Nature explores the most-cited research of all time.

    The top 100 papers Nature explores the most-cited research of all time. The discovery of high-temper ...