• F(x)


     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<algorithm>
     5 using namespace std;
     6 
     7 const int maxn=1e4+5;
     8 
     9 int A,B,sum;
    10 int num[40],dp[40][maxn];
    11 
    12 int F(int x){
    13     if(x==0) return 0;
    14     int ans=F(x/10);
    15     return ans*2+(x%10);
    16 } 
    17 
    18 int DFS(int pos,int res,bool F){
    19     if(pos==-1) return res<=sum;
    20     if(res>sum) return 0;
    21     if(!F&&dp[pos][sum-res]!=-1) return dp[pos][sum-res];
    22     
    23     int maxv=F?num[pos]:9;
    24     int ans=0;
    25     for(int i=0;i<=maxv;i++) ans=ans+DFS(pos-1,res+i*(1<<pos),F&&i==maxv);
    26     
    27     if(!F) dp[pos][sum-res]=ans;
    28     return ans;
    29 }
    30 
    31 int Solve(int temp){
    32     if(temp==0) return 1;
    33     int cnt=0;
    34     while(temp){
    35         num[cnt++]=temp%10;
    36         temp/=10;
    37     }
    38     return DFS(cnt-1,0,true);
    39 }
    40 
    41 int main()
    42 {   int kase;
    43     cin>>kase;
    44     memset(dp,-1,sizeof(dp));            //放在循坏里面会超时
    45     for(int t=1;t<=kase;t++){
    46         cin>>A>>B;
    47         sum=F(A);
    48         printf("Case #%d: %d
    ",t,Solve(B));
    49     }
    50     return 0;
    51 }
     1 int DFS(int pos,int res,bool F){
     2     if(res>sum) return 0;           
     3     if(pos==-1) return 1;
     4     if(!F&&dp[pos][sum-res]!=-1) return dp[pos][sum-res];
     5     
     6     int maxv=F?num[pos]:9;
     7     int ans=0;
     8     for(int i=0;i<=maxv;i++) ans=ans+DFS(pos-1,res+i*(1<<pos),F&&i==maxv);
     9     
    10     if(!F) dp[pos][sum-res]=ans;
    11     return ans;
    12 }
  • 相关阅读:
    [CF1028D] Order book
    初入python,与同学者的第一次见面(小激动)
    jira与mysql的配合搭建调整
    linux内置的审计跟踪工具------last和lastb
    rman
    nginx和apache的一些比较
    NYOJ128前缀式计算
    NYOJ2括号配对问题
    大数加减乘以及高精度幂
    在不同的页面之间通过查询字符串传递信息
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/7567768.html
Copyright © 2020-2023  润新知