windy数

基本的数位DP,需要判断当前位是否为起始位。

#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std; #define D(x) x const int MAX_DIGIT = ; int n, m;
int f[MAX_DIGIT];
int memoize[MAX_DIGIT][][][]; void to_digits(int a)
{
for (int i = ; i < MAX_DIGIT; i++)
{
f[i] = a % ;
a /= ;
}
} int dfs(int digit, bool less, bool first, int last)
{
if (digit == -)
{
return ;
}
if (memoize[digit][less][first][last] != -)
{
return memoize[digit][less][first][last];
}
int limit = less ? : f[digit];
int ret = ;
for (int i = ; i <= limit; i++)
{
if (!first && abs(i - last) < )
{
continue;
}
ret += dfs(digit - , less || i < f[digit], first && i == , i);
}
memoize[digit][less][first][last] = ret;
return ret;
} int main()
{
scanf("%d%d", &n, &m);
n--;
to_digits(n);
memset(memoize, -, sizeof(memoize));
int ans_n = dfs(, false, true, );
to_digits(m);
memset(memoize, -, sizeof(memoize));
int ans_m = dfs(, false, true, );
printf("%d\n", ans_m - ans_n);
return ;
}

UESTC 250的更多相关文章

  1. UESTC 250 windy数(数位DP)

    题意:题意:求区间[A,B]之间的,不含前导0,且相邻两数位之间相差至少为2的正整数有多少个. 分析:dp[i][j]表示,长度为i.以j为结尾的表示的个数,再加一个前导0判断即可 #include ...

  2. uestc 250 数位dp(水)

    /* 数位dp 水题 开两维一个记录长度,一个记录上一个数 */ #include<stdio.h> #include<string.h> #define N 13 int d ...

  3. uestc 250 windy数(数位dp)

    题意:不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B之间,包括A和B,总共有多少个windy数? 思路:数位dp #include<iostream ...

  4. 数位DP题目汇总

    Google Code Jam 2014 Round 1B Problem B hdu 2089 hdu 3555 uestc 250 (原1307) hdu 3652 hdu 3709 Light ...

  5. UESTC 1851 Kings on a Chessboard

    状压DP... Kings on a Chessboard Time Limit: 10000ms Memory Limit: 65535KB This problem will be judged ...

  6. ACM:UESTC - 649 括号配对问题 - stack

      UESTC - 649  括号配对问题 Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu ...

  7. 免费素材:包含 250+ 组件的 DO UI Kit

    DO UI kit 现在可以免费用于 Photoshop 和 Sketch 了.它有超过130个屏幕,10个完整的主题以及250+的组件混合以创造惊人的应用.他们都是再混合和视网膜.最重要的是他们看起 ...

  8. UESTC 1015 Lweb and pepper --前,后缀最值

    题意: n种食物,每种含花椒的概率为Pi,现在已经选择了[L,R]这个区间(下标)的食物,要再选一个,使总的食物只有一种含花椒的概率最大,问选哪个最好,相同的选下标小的. 解法: 就不写解法了.此处有 ...

  9. UESTC 1852 Traveling Cellsperson

    找规律水题... Traveling Cellsperson Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged ...

随机推荐

  1. 浅谈JavaScript中的正则表达式

    引言 对于正则表达式我想作为程序员肯定使用过它,那天书般的表达方式,我用一次就记住它了.这篇博客先介绍一些正则表达式的内容,然后介绍JavaScript中对正则表达式特有的改进.下面开始介绍正则表达式 ...

  2. php中pdo例子

    下面是从其他博客看到的代码 <?php $dbh = new PDO('mysql:host=localhost;dbname=access_control', 'root', ''); $db ...

  3. R语言演示功能

    大家熟知的画图ggplot2包 library(ggplot2) #查看系统自带的qplot的函数演示 example(qplot) #R语言的基本对象 向量.矩阵.数组.数据框.列表 R语言的变量都 ...

  4. 关于Mysql错误:./bin/mysqld_safe --user=mysql& [1] 32710 121003 16:40:22 mysqld_safe Logging to '/var/log/mysqld.log'. 121003 16:40:22 mysqld_s

    [root@www]# ./bin/mysqld_safe --user=mysql&[1] 32710[root@www]# 121003 16:40:22 mysqld_safe Logg ...

  5. CF461B Appleman and Tree (树DP)

    CF462D Codeforces Round #263 (Div. 2) D Codeforces Round #263 (Div. 1) B B. Appleman and Tree time l ...

  6. CF459B Pashmak and Flowers (水

    Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...

  7. C#中的那些全局异常捕获

    1.WPF全局捕获异常     public partial class App : Application     {         public App()         {    // 在异 ...

  8. ASP CDONTS.NEWMAIL组件发送电邮(附下载)

    附CDONT.NEWMAIL组件下载地址:http://files.cnblogs.com/files/colinliu/cdonts.rar ASP常规发送方法: <% dim mail se ...

  9. iOS中assign,copy,retain之间的区别以及weak和strong的区别(面试)

    • copy: 用于希望保持一份传入值的拷贝,而不是值自身的情况,即把原来的对象完整的赋值到另外一地方,重新加载一内存区,一个地方变了不影响另一个地方的对象. • assign:  简单的直接赋值,相 ...

  10. 利用PHP读取文件

    $fp=fopen("D:\\phpStudy\\www\\date\\file\\2.txt","r");if($fp){    while(!feof($f ...