数位DP。dp[i][j]表示i位,最高位为j的情况下总共有多少1.

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std; long long dp[][];
char s[]; void init()
{
memset(dp,,sizeof dp); long long num=; for(int i=; i<=; i++)
{
for(int j=; j<=; j++)
{
if(j==) dp[i][j]=num;
for(int s=; s<=; s++)
dp[i][j]=dp[i][j]+dp[i-][s];
}
num=num*;
} } int main()
{
init();
while(~scanf("%s",s))
{
int len=strlen(s);
long long n=;
for(int i=; s[i]; i++) n=n*+s[i]-'';
long long ans=; for(int i=; i<s[]-''; i++) ans=ans+dp[len][i];
for(int i=; s[i]; i++)
{
int d=len-i;
for(int j=; j<s[i]-''; j++) ans=ans+dp[d][j];
}
long long x=;
for(int i=; s[i]; i++)
{
x=x*+s[i]-'';
if(s[i]=='')
{
long long tmp=x;
for(int j=i+; s[j]; j++) tmp=tmp*;
ans=ans+n-tmp+;
}
}
printf("%lld\n",ans);
}
return ;
}

PAT (Advanced Level) 1049. Counting Ones (30)的更多相关文章

  1. PAT (Advanced Level) 1004. Counting Leaves (30)

    简单DFS. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...

  2. PAT 解题报告 1049. Counting Ones (30)

    1049. Counting Ones (30) The task is simple: given any positive integer N, you are supposed to count ...

  3. PAT (Advanced Level) 1115. Counting Nodes in a BST (30)

    简单题.统计一下即可. #include<cstdio> #include<cstring> #include<cmath> #include<vector& ...

  4. 【PAT甲级】1049 Counting Ones (30 分)(类似数位DP思想的模拟)

    题意: 输入一个正整数N(N<=2^30),输出从1到N共有多少个数字包括1. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include& ...

  5. PAT (Advanced Level) 1111. Online Map (30)

    预处理出最短路再进行暴力dfs求答案会比较好.直接dfs效率太低. #include<cstdio> #include<cstring> #include<cmath&g ...

  6. PAT (Advanced Level) 1107. Social Clusters (30)

    简单并查集. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...

  7. PAT (Advanced Level) 1103. Integer Factorization (30)

    暴力搜索. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  8. PAT (Advanced Level) 1072. Gas Station (30)

    枚举一下选的位置,每次算一下就可以了. #include<cstdio> #include<cstring> #include<cmath> #include< ...

  9. PAT (Advanced Level) 1091. Acute Stroke (30)

    BFS求连通块.递归会爆栈. #include<cstdio> #include<cstring> #include<cmath> #include<algo ...

随机推荐

  1. A框架 第二部 实例化接收到的get类,调用父类抽象方法,自动执行方法call_user_func_array()

    01父类抽象类 abstract.php <?phpabstract class controller_abstract{ protected $app; function __construc ...

  2. 1213 How Many Tables 简单的并查集问题

    my code: #include <cstdio>#include <cstring>#include<iostream>using namespace std; ...

  3. Android实现Excel表格,且表格能左右、上下滑动

    1.自定义实现一个水平滚动控件HorizontalScrollView import android.content.Context; import android.util.AttributeSet ...

  4. <marquee>,视频和音频的插入,正则表达式

    1.marquee 页面的自动滚动效果,不仅可以移动文字,也可以移动图片表格. <marquee></marquee>之间加内容即可. marquee的属性 1.滚动方向dir ...

  5. ubuntu下 编译Caffe的Matlab接口

    一般情况下不愿意使用Caffe的Matlab接口,总觉得Linux版的Matlab很难配置,但是现在搞目标检测,得到的源码是使用的Caffe的Matlab接口,只能硬着头皮上了. (1)修改caffe ...

  6. [QML] Connections元素介绍

    一个Connections对象创建一个了一个QML信号的连接.在QML中,我们连接信号通常是用使用"on<Signal>"来处理的,如下所示: MouseArea { ...

  7. php中header函数参数的 Cache-control:private,no-cache,must-revalidate,max-age 使用方法

    网页的缓存是由HTTP消息头中的“Cache-control”来控制的,常见的取值有private.no-cache.max-age.must-revalidate等,默认为private.其作用根据 ...

  8. asp发邮件控件

    <% Set jmail = Server.CreateObject("JMAIL.SMTPMail") ’创建一个JMAIL对象 jmail.silent = true ’ ...

  9. redis采用序列化方案存对象

    前几天被问到这样一个问题,redis怎么存对象,平时也没怎么注意,只知道redis存字符之类的,不过就是根据键存取值,不过对象的话还是不同的 首先来了解一下为什么要实现序列化 为什么要实现序列化接口 ...

  10. php中获取各种路径

    echo $_SERVER['DOCUMENT_ROOT'].""; //获得服务器文档根 echo $_SERVER['PHP_SELF'].""; //获得 ...