zoukankan      html  css  js  c++  java
  • URAL 1057. Amount of Degrees(数位DP)

    题目链接

    我看错题了。。。都是泪啊,不存在3*4^2这种情况。。。系数必须为1。。。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <vector>
     5 using namespace std;
     6 #define LL long long
     7 int num[60];
     8 LL dp[60][60];
     9 int k,b;
    10 LL dfs(int pos,int pre,int bound)
    11 {
    12     int i,end;
    13     LL ans = 0;
    14     if(pos == -1)
    15     return pre == 0;
    16     if(pre < 0)
    17     return 0;
    18     if(!bound&&dp[pos][pre] != -1)
    19     return dp[pos][pre];
    20     end = bound ? num[pos]:b-1;
    21     for(i = 0;i <= end;i ++)
    22     {
    23         if(i == 0)
    24         ans += dfs(pos-1,pre,bound&&i == end);
    25         else if(i == 1)
    26         ans += dfs(pos-1,pre-1,bound&&i == end);
    27     }
    28     if(!bound)
    29     dp[pos][pre] = ans;
    30     return ans;
    31 }
    32 LL judge(LL x)
    33 {
    34     int pos = 0;
    35     while(x)
    36     {
    37         num[pos++] = x%b;
    38         x /= b;
    39     }
    40     return dfs(pos-1,k,1);
    41 }
    42 int main()
    43 {
    44     LL x,y;
    45     memset(dp,-1,sizeof(dp));
    46     cin>>x>>y>>k>>b;
    47     cout<<judge(y)-judge(x-1)<<endl;
    48     return 0;
    49 }
  • 相关阅读:
    Python paramiko安装报错
    Python 函数返回值类型
    python 数据类型
    python — 模块(二)
    python — 模块(一)
    python 总结
    python 小知识3
    python 小知识3
    python 小知识2
    python — 计算机基础知识
  • 原文地址:https://www.cnblogs.com/naix-x/p/3399820.html
Copyright © 2011-2022 走看看