zoukankan      html  css  js  c++  java
  • hdu4734F(x)(dp)

    http://acm.hdu.edu.cn/showproblem.php?pid=4734

    各种不细心啊  居然算的所有和最大值会小于1024.。。

    第二次做数位DP  不是太熟

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<stdlib.h>
     6 #include<cmath>
     7 using namespace std;
     8 #define LL __int64
     9 int dp[15][10500],dp2[15][10500];
    10 int a,b;
    11 int pp[20];
    12 void init()
    13 {
    14     int i,j,g;
    15     pp[0] = 1;
    16     for(i = 1 ; i <= 11 ; i++)
    17     pp[i] = pp[i-1]*2;
    18     for(i = 0 ; i <= 9 ; i++)
    19     dp[1][i] = 1;
    20     for(i = 2 ; i <= 11 ; i++)
    21     {
    22         for(g = 0 ; g <= 9 ; g++)
    23         {
    24             for(j = 0 ; j <= 10054 ; j++)
    25             {
    26                 if(j+g*pp[i-1]>10054)
    27                 continue;
    28                 dp[i][j+pp[i-1]*g] += dp[i-1][j];
    29             }
    30         }
    31     }
    32     for(i = 1 ;  i <= 11 ; i++)
    33     {
    34         for(j = 1 ; j <= 10054 ; j++)
    35         {
    36             dp[i][j] += dp[i][j-1];
    37         }
    38     }
    39 }
    40 int fc(LL x)
    41 {
    42     int s=0,o=0;
    43     while(x)
    44     {
    45         s+=(x%10)*pp[o];
    46         x/=10;
    47         o++;
    48     }
    49     return s;
    50 }
    51 int main()
    52 {
    53     int i,g,t,p[20],kk=0;
    54     init();
    55     scanf("%d",&t);
    56     while(t--)
    57     {
    58         kk++;
    59         scanf("%d%d",&a,&b);
    60         int s1 = fc(a);
    61         LL y = b;
    62         int o=0;
    63         while(y)
    64         {
    65             o++;
    66             p[o] = y%10;
    67             y/=10;
    68         }
    69         int ans=0;
    70         int ts=0;
    71         for(i = o ; i>= 1; i--)
    72         {
    73             for(g = 0 ; g < p[i] ; g++)
    74             {
    75                 int tt = ts+pp[i-1]*g;
    76                 if(i==1)
    77                 {
    78                     if(tt<=s1)
    79                     ans++;
    80                     continue;
    81                 }
    82                 if(tt>s1)
    83                 break;
    84                 ans+=dp[i-1][s1-tt];
    85             }
    86             ts += p[i]*pp[i-1];
    87         }
    88         if(fc(b)<=s1)
    89         ans++;
    90         printf("Case #%d: ",kk);
    91         printf("%d
    ",ans);
    92     }
    93     return 0;
    94 }
    View Code
  • 相关阅读:
    CHOCBase
    iOS 12中无法获取WiFi的SSID了?
    如何打开Assets.car文件
    博客园美化资源网站链接
    xcode工程配置绝对路径与相对路径
    UIControl事件
    UIButton属性
    UIAlertView
    UIActivityIndicatorView
    NSAttributedString
  • 原文地址:https://www.cnblogs.com/shangyu/p/3321729.html
Copyright © 2011-2022 走看看