HDU6148

简单的数位DP。只需要判断是否在递减之前出现过递增
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define nl n<<1
#define nr (n<<1)|1
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f;
const ll INFF=0x3f3f3f3f3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-9;
const ll mod=1e9+7;
int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' | ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void Out(int aa)
{
    if(aa>9)
        Out(aa/10);
    putchar(aa%10+'0');
}
long long dp[105][105][10][2][2];
int s[105];
char str[105];
ll rec(int i,int pre,int up,int down,int flag,int q,int len)
{
    if(i<0)
        return 1;
    if(dp[i][len][pre][up][down]!=-1&&!flag&&!q)
        return dp[i][len][pre][up][down];
    ll res=0;
    int o=s[i];
    for(int j=0; j<10; j++)
    {
        if(j>o&&flag)
            break;
        if(q)
            res+=rec(i-1,j,0,0,j<o?0:flag,q&&j==0,len-(q&&j==0)),res%=mod;
        else if(j==pre)
        {
            res+=rec(i-1,j,up,down,j<o?0:flag,q&&j==0,len),res%=mod;
        }
        else if(j>pre)
        {
            res+=rec(i-1,j,1,down,j<o?0:flag,q&&j==0,len),res%=mod;
        }
        else if(j<pre)
        {
            if(up)
                continue;
            res+=rec(i-1,j,up,1,j<o?0:flag,q&&j==0,len),res%=mod;
        }
    }
    if(!flag&&!q)
        dp[i][len][pre][up][down]=res;
    return res;
}
long long cal()
{
    int len=strlen(str);
    for(int i=0; i<len; i++)
    {
        s[i]=str[len-1-i]-'0';
        //printf("%d\n",s[i]);
    }
    return rec(len-1,0,0,0,1,1,len);
}
int main()
{
    memset(dp,-1,sizeof(dp));
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",str);
        printf("%I64d\n",(cal()-1+mod)%mod);
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值