[数位DP] BZOJ 2713 [Violet 2]愚蠢的副官 & BZOJ 1183 [Croatian2008]Umnozak

官方题解

The first observation we can make is that, for all positive integers x , the digit-product p(x) is always less than or equal to x . From xp(x)B1018 we can deduce that p(x)B109
Because p(x) is a product of digits, its prime factors can only be 2 , 3, 5 and 7. The number of different integers with only 2 , 3, 5 and 7 in their prime factorization that are less than or equal to 109 is quite small (exactly 5194 ).

然后就很显然了
枚举出 p(x) 然后找小于等于 n/p(x) 的满足条件的 x <script type="math/tex" id="MathJax-Element-2406">x</script>
简单的数位DP 我不顾及复杂度地乱写一通竟然过了
为什么std跑的那么快 嘤嘤嘤

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;

const int fact[]={2,3,5,7};  
const int C[11][4]={  
  {0,0,0,0}, 
  {0,0,0,0}, 
  {1,0,0,0}, 
  {0,1,0,0}, 
  {2,0,0,0}, 
  {0,0,1,0}, 
  {1,1,0,0}, 
  {0,0,0,1}, 
  {3,0,0,0}, 
  {0,2,0,0}  
};
int f[25][45][35][25][25];

inline ll count(ll n,int a,int b,int c,int d){
  if (!n) return 0;
  int w[20]={0},m=0; n++;
  for (ll t=n;t;w[++m]=t%10,t/=10); reverse(w+1,w+m+1);
  for (int t=1;t<=m;t++)
    for (int i=0;i<=a;i++)
      for (int j=0;j<=b;j++)
    for (int k=0;k<=c;k++)
      for (int l=0;l<=d;l++) f[t][i][j][k][l]=0;
  int p[4]={0}; int flag=0;
  for (int t=1;t<=m;t++){
    for (int r=1;r<=9;r++)
      for (int i=0;i+C[r][0]<=a;i++)
    for (int j=0;j+C[r][1]<=b;j++)
      for (int k=0;k+C[r][2]<=c;k++)
        for (int l=0;l+C[r][3]<=d;l++)
          f[t][i+C[r][0]][j+C[r][1]][k+C[r][2]][l+C[r][3]]+=f[t-1][i][j][k][l];
    if (!flag)
      for (int r=1;r<w[t];r++)
    f[t][p[0]+C[r][0]][p[1]+C[r][1]][p[2]+C[r][2]][p[3]+C[r][3]]++;
    if (t!=1){
      for (int r=1;r<=9;r++)
    f[t][C[r][0]][C[r][1]][C[r][2]][C[r][3]]++;
    }
    if (!w[t])
      flag=1;
    else
      for (int i=0;i<4;i++)
    p[i]+=C[w[t]][i];
  }
  return f[m][a][b][c][d];
}

inline ll Solve(ll n){
  if (!n) return 0;
  ll a,b,c,d; int i,j,k,l; ll B=sqrt(n);
  ll ret=0;
  for (i=0,a=1;a<=B;i++,a*=fact[0])
    for (j=0,b=a;b<=B;j++,b*=fact[1])
      for (k=0,c=b;c<=B;k++,c*=fact[2])
    for (l=0,d=c;d<=B;l++,d*=fact[3])
      ret+=count(n/d,i,j,k,l);
  return ret;
}

int main(){
  ll L,R;
  freopen("t.in","r",stdin);
  freopen("t.out","w",stdout);
  scanf("%lld%lld",&L,&R);
  printf("%lld\n",Solve(R)-Solve(L-1));
  return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值