zoukankan      html  css  js  c++  java
  • bzoj 1026: [SCOI2009]windy数

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1026

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

    解:数位dp,状态末尾的0是无限制,1是有限制

     1 /*
     2  * Problem:  
     3  * Author:  SHJWUDP
     4  * Created Time:  2015/6/4 星期四 11:04:39
     5  * File Name: 233.cpp
     6  * State: 
     7  * Memo: 
     8  */
     9 #include <iostream>
    10 #include <cstdio>
    11 #include <cstring>
    12 #include <algorithm>
    13 
    14 using namespace std;
    15 
    16 typedef long long int64;
    17 
    18 const int MaxA=10+7;
    19 
    20 int f[MaxA][MaxA][2];    //f[][][1]:limit
    21 int arr[MaxA], num;
    22 int func(int x) {
    23     if(x<10) return x;
    24     num=0;
    25     do {
    26         arr[num++]=x%10;
    27         x/=10;
    28     } while(x);
    29     memset(f, 0, sizeof(f));
    30     for(int i=1; i<arr[num-1]; i++) f[num-1][i][0]=1;
    31     f[num-1][arr[num-1]][1]=1;
    32     for(int i=num-1; i>0; i--) {
    33         for(int j=0; j<=9; j++) {
    34             for(int k=0; k<=9; k++) {
    35                 if(abs(j-k)>=2) {
    36                     f[i-1][k][0]+=f[i][j][0];
    37                     if(k<arr[i-1]) f[i-1][k][0]+=f[i][j][1];
    38                     else if(k==arr[i-1]) f[i-1][k][1]+=f[i][j][1];
    39                 }
    40             }
    41             if(j!=0) f[i-1][j][0]++;    ///leading zeros
    42         }
    43     }
    44     int res=0;
    45     for(int i=0; i<=9; i++) {
    46         res+=f[0][i][0]+f[0][i][1];
    47     }
    48     return res;
    49 }
    50 int main() {
    51 #ifndef ONLINE_JUDGE
    52     freopen("in", "r", stdin);
    53     //freopen("out", "w", stdout);
    54 #endif
    55     int A, B;
    56     while(~scanf("%d%d", &A, &B)) {
    57         printf("%d
    ", func(B)-func(A-1));
    58     }
    59     return 0;
    60 }
    View Code
  • 相关阅读:
    Maven 环境的配置
    zTree的简单例子
    plsql免安装客户端的配置
    HDU 1232 畅通工程
    HDU 5698 瞬间移动
    Codeforces 1015E1 Stars Drawing (Easy Edition)
    Codeforces 784B Santa Claus and Keyboard Check
    Codeforces 500C New Year Book Reading
    NSarray 赋值 拷贝 等问题记录
    UINavigationController 操作记录
  • 原文地址:https://www.cnblogs.com/shjwudp/p/4551633.html
Copyright © 2011-2022 走看看