• hdu 6148 Valley Numer


    http://acm.hdu.edu.cn/showproblem.php?pid=6148

    dp[i][j][0/1]表示第i位,上一位填的是j,这一位能否随便填

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    
    using namespace std;
    
    #define N 101
    const int mod=1e9+7;
    
    int dp[N][10][2];
    int a[N];
    
    char s[N]; 
    
    int dfs(int dep,int last,bool lim,int free,bool zero)
    {
        if(!lim && dp[dep][last][free]!=-1) return dp[dep][last][free];
        if(!dep) return !zero;
        int sum=0,up=lim ? a[dep] : 9,down=free ? 0 : last;
        for(int i=down;i<=up;++i)
        {
            sum+=dfs(dep-1,i,lim && i==a[dep],free && (i<=last||zero),zero && !i);
            sum%=mod;
        }
        if(!lim && !zero) dp[dep][last][free]=sum;
        return sum;
    }
    
    int main()
    {
         int T,n;
         scanf("%d",&T);
         while(T--)
         {
             scanf("%s",s+1);
             n=strlen(s+1);
             reverse(s+1,s+n+1);
             for(int i=1;i<=n;++i) a[i]=s[i]-'0';
             memset(dp,-1,sizeof(dp)); 
            printf("%d
    ",dfs(n,0,1,1,1));
         }
         return 0;
    }

    Valley Numer

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1847    Accepted Submission(s): 936


    Problem Description
    众所周知,度度熊非常喜欢数字。

    它最近发明了一种新的数字:Valley Number,像山谷一样的数字。




    当一个数字,从左到右依次看过去数字没有出现先递增接着递减的“山峰”现象,就被称作 Valley Number。它可以递增,也可以递减,还可以先递减再递增。在递增或递减的过程中可以出现相等的情况。

    比如,1,10,12,212,32122都是 Valley Number。

    121,12331,21212则不是。

    度度熊想知道不大于N的Valley Number数有多少。

    注意,前导0是不合法的。
     
    Input
    第一行为T,表示输入数据组数。

    每组数据包含一个数N。

    ● 1≤T≤200

    ● 1≤length(N)≤100
     
    Output
    对每组数据输出不大于N的Valley Number个数,结果对 1 000 000 007 取模。
     
    Sample Input
    3 3 14 120
     
    Sample Output
    3 14 119
     
    Source
     
    Recommend
    We have carefully selected several similar problems for you:  6742 6741 6740 6739 6738
  • 相关阅读:
    爬虫(一)—— 爬取一个简单的网站
    Neutron的安全组原理
    Neutron的防火墙原理
    Openstack Mitaka 负载均衡 LoadBalancerv2
    iptables(四)iptables匹配条件总结之一
    iptables(三)iptables规则管理(增、删、改)
    iptables(二)iptables实际操作之规则查询
    iptables(一)iptables概念
    opensack-mitaka网络性能测试shaker
    neutron二层网络实现
  • 原文地址:https://www.cnblogs.com/TheRoadToTheGold/p/12379989.html
Copyright © 2020-2023  润新知