数位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. select 1 from table

    1.select 1 from mytable;与select anycol(目的表集合中的任意一行) from mytable;与select * from mytable 作用上来说是没有差别的, ...

  2. 第13章 Swing程序设计

    1.Swing概述 GUI(图形用户界面)为程序提供图形界面,最初的设计目的是为程序员构建一个通用的GUI,使其能够在所有平台上运行.但Java 1.0中基础类AWT(抽象窗口工具箱)并没有达到这个要 ...

  3. 网络请求 get post

    1.新建一个网络请求工具类,负责整个项目中所有的Http网络请求 提示:同步请求会卡住线程,发送网络请求应该使用异步请求(这意味着类方法不能有返回值) 2.工具类的实现 YYHttpTool.h文件 ...

  4. Masonry使用详解

    mas_makeConstraints 只负责新增约束 Autolayout不能同时存在两条针对于同一对象的约束 否则会报错 mas_updateConstraints 针对上面的情况 会更新在blo ...

  5. Spring Security-用户密码自定义加密

    public class SunPasswordEncoder implements PasswordEncoder{ //@实现加密的方法,既将明文转换为密文的方法 public String en ...

  6. SSH returns “too many authentication failures” error – HostGator

    I am an avid fan of using HostGator for small business WordPress website hosting. I love that they u ...

  7. DataSet与DataReader的比较

    DataSet与DataReader的比较 DataSet DataReader 读或写数据 只读 包含多个来自不同数据库的表 使用 SQL 语句从单个数据库 非连接模式 连接模式 绑定到多个控件 只 ...

  8. vs找不到svn源代码管理插件之我见

    使用svn要安装两个文件,一个客户端:TortoiseSVN-1.8.msi,一个插件:AnkhSvn-2.5.msi:两个都安装好之后,在vs的tool(工具)选项卡中,选择自定义,然后选择sour ...

  9. Bitmap与Matrix旋转ImageView

    Bitmap与Matrix旋转ImageView 标签: matrixfloatbutton测试importlayout 2010-08-23 22:18 8569人阅读 评论(0) 收藏 举报  分 ...

  10. HDU1233--还是畅通工程(最小生成树)

    Problem Description 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府"畅通工程"的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直 ...