zoukankan      html  css  js  c++  java
  • H

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <string>
     6 using namespace std;
     7 typedef long long ll;
     8 
     9 const int maxn = 1e4+5;
    10 int dp[15][maxn];    //pos sum
    11 int Max;
    12 int aa[15];
    13 
    14 int f(int x){
    15     int ans = 0;
    16     int cnt = 1;
    17     while(x){
    18         ans = ans + x%10*cnt;
    19         x /= 10;
    20         cnt *= 2;
    21     }
    22     return ans;
    23 }
    24 
    25 int dfs(int pos, int sum, bool limit){
    26     if(pos == -1) return sum <= Max;    //是否满足条件
    27     if(sum > Max) return 0;
    28     if(!limit && dp[pos][Max - sum] != -1)
    29         return dp[pos][Max - sum];
    30     int up = limit?aa[pos]:9;
    31     int ans = 0;
    32     for(int i = 0; i <= up;i++){
    33         ans += dfs(pos-1, sum+ i*(1<<pos), limit&&i == aa[pos]);
    34     }
    35     if(!limit) dp[pos][Max - sum] = ans;
    36     return ans;
    37 }
    38 
    39 int solve(int x){
    40     int pos = 0;
    41     while(x){
    42         aa[pos++] = x%10;
    43         x /= 10;
    44     }
    45     return dfs(pos-1, 0, true);    //最高位是有限制的
    46 }    
    47 
    48 int main(){
    49     memset(dp, -1, sizeof dp);
    50     int t;
    51     scanf("%d", &t);
    52     int Case = 0;
    53     while(t--){
    54         // memset(dp, -1, sizeof(dp));
    55         Case++;
    56         int a, b;
    57         scanf("%d%d", &a, &b);
    58         Max = f(a);
    59         int ans = solve(b);
    60         printf("Case #%d: %d
    ", Case, ans);
    61     }
    62     return 0;
    63 }

    H - F(x)

  • 相关阅读:
    Windows ETW 学习与使用三
    暗云Ⅳ对SATA磁盘MBR Hook探索
    msahci代码调试备份
    mimikatz使用命令记录
    Windows ETW 学习与使用一
    RabbitMQ 实现延迟队列
    Redis 脱坑指南
    浅析 ThreadLocal
    IDEA2020.2.3破解
    用友NC 模块 简写(瞎猜的)
  • 原文地址:https://www.cnblogs.com/ouyang_wsgwz/p/9112901.html
Copyright © 2011-2022 走看看