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;
    }
  • 相关阅读:
    Python中怎么使用(冒泡排序)?
    Python中怎么定义与调用(函数)
    简易购物商城(1.0)版本
    非空即真 和 切片 处理方式
    python模块-random
    内置函数
    多维数组
    函数扩展
    文件操作扩展2
    文件操作扩展
  • 原文地址:https://www.cnblogs.com/yigexigua/p/3901678.html
Copyright © 2011-2022 走看看