zoukankan      html  css  js  c++  java
  • Hdu3079Balanced Number数位dp

    枚举支点,然后就搞,记录之前的点的力矩和。

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <climits>
    #include <string>
    #include <iostream>
    #include <map>
    #include <cstdlib>
    #include <list>
    #include <set>
    #include <queue>
    #include <stack>
    #include<math.h>
    using namespace std;
    typedef long long LL;
    
    LL up[100];LL dp[30][30][2000];
    LL dfs(LL x,LL pos,LL pre,LL flag)
    {
        if(x<=0) return pre==0;
        if(pre<0) return 0;
        if(!flag&&~dp[x][pos][pre]) return dp[x][pos][pre];
        LL limit= flag? up[x]: 9,ret= 0;
        for(LL i = 0;i<= limit;i++){
            ret+=dfs(x-1,pos,pre+(x - pos )* i ,flag&&i==limit) ;
        }
        return flag? ret : dp[x][pos][pre]= ret;
    }
    LL solve(LL x)
    {
        LL len=0;
        while(x){
            up[++len]=x%10;
            x/=10;
        }
        LL ans=0;
        for(LL i = 1;i<= len;i++)
            ans+=dfs(len,i,0,1);
        return ans-len ;
    
    }
    int main()
    {
        LL Icase;LL n,m;
        scanf("%d",&Icase);
        memset(dp,-1,sizeof(dp));
        while(Icase--){
            cin>>n>>m;
            cout<<solve(m) - solve(n-1) <<endl;
        }
        return 0;
    }
  • 相关阅读:
    java命令模式
    java中介者模式
    java访问者模式
    java状态模式
    java责任链模式
    java策略模式(及与工厂模式的区别)
    github token 位置
    Yii2 Queue队列
    sz与rz
    vim
  • 原文地址:https://www.cnblogs.com/yigexigua/p/3901678.html
Copyright © 2011-2022 走看看