为了搞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. Windows程序设计 贪吃蛇c

    看Windows程序有段时间了,终于动手写东西.贪吃蛇算是一个开始吧,下面的贪吃蛇很简单,也有很多地方需要修改,还有情况没有考虑QAQ 但这不是我的目的了... 思路很简单:建个链表储存蛇身节点即可. ...

  2. Xcode编译项目出现访问private key提示框

    原因: 在编译时Xcode进行codesign时需要访问"private key"时没有权限,然后让询问是否允许,有三个选项,全部允许.否绝.允许,一次弹出4个(我遇到的) 遇到问 ...

  3. Windows7 IIS7 无法启动计算机上的服务W3SVC如何修复

    错误提示 启动iis7管理服务器提示:无法启动计算机上的服务W3SVC 启动Windows Process Activation Service服务,报错:6801 指定资源管理器中的事务支持未启动或 ...

  4. Html5的<button>标签

    1.标签是双标签,其内可添加文字,图片等复杂的样式. ​2.不仅可以在表单中使用,还可以在其他块元素和内联元素中使用. 3.一般在input标签内添加name属性,否则提交后不显示.

  5. SQL 左外连接查询 将右表中的多行变为左表的一列或多列

    示例: --行列互转 /**************************************************************************************** ...

  6. WdatePicker.js 日期时间插件

    支持功能: 1.支持常规在input单击或获得焦点时调用,还支持使用其他的元素如:<img><div>等触发WdatePicker函数来调用弹出日期框 @1.input 调用: ...

  7. iOS uuchart 用法

    这个是 画 折线图用的 一个 第三方文件 说白了就是一个  用 贝塞尔 曲线封装好的一个  第三方. 但是有机会还是需要看下怎么用

  8. 如何用extjs显示一个已经存在的页面

    最近碰到了一个需求: 画面上有个按钮,点击了按钮之后,弹出一个窗体(window),而该窗体(window)上显示的内容是某个系统的内容,如下图所示 查了好长时间的extjs的帮助文档,没有找个现成的 ...

  9. A Statistical View of Deep Learning (IV): Recurrent Nets and Dynamical Systems

    A Statistical View of Deep Learning (IV): Recurrent Nets and Dynamical Systems Recurrent neural netw ...

  10. 【HDOJ】1903 Exchange Rates

    水DP.精度很坑. /* hdoj 1903 */ #include <cstdio> #include <cstring> #include <cstdlib> ...