G - B-number
#include<stdio.h>
#include<string.h>
using namespace std;
typedef long long ll; int a[];
int dp[][][]; //pos:当前位置
//mod:余数
//have :0:前一位不是1 1:前一位是1 2:有13
ll dfs(int pos,int mod,int have,bool limit){
if(pos==-) return mod == && have == ;
if(!limit && dp[pos][mod][have] != -)
return dp[pos][mod][have];//没有上限并且已被访问过
int up = limit?a[pos]:;
ll ans = ,i;
for(i = ;i <= up;i++){
int modx = (mod*+i)%;
int havex = have;
if(have == && i==) havex=;
if(have == && i!=) havex=;
if(have == && i == ) havex=;
ans += dfs(pos-, modx, havex, limit && i == a[pos]);
}
if(!limit) dp[pos][mod][have] = ans;
return ans;
} ll solve(ll x){
int pos=;
while(x){
a[pos++]=x%;
x/=;
}
return dfs(pos-,,,true);
}
int main(){
ll n;
memset(dp,-,sizeof(dp));
while(scanf("%lld",&n)!=EOF){
ll ans = solve(n);
printf("%lld\n",ans;
}
return ;
}
G - B-number的更多相关文章
- CF 724 G. Xor-matic Number of the Graph
G. Xor-matic Number of the Graph 链接 题意: 给定一个无向图,一个interesting的三元环(u,v,s)满足,从u到v的路径上的异或和等于s,三元环的权值为s, ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) G - Xor-matic Number of the Graph 线性基好题
G - Xor-matic Number of the Graph 上一道题的加强版本,对于每个联通块需要按位算贡献. #include<bits/stdc++.h> #define LL ...
- G - Harmonic Number (II) 找规律--> 给定一个数n,求n除以1~n这n个数的和。n达到2^31 - 1;
/** 题目:G - Harmonic Number (II) 链接:https://vjudge.net/contest/154246#problem/G 题意:给定一个数n,求n除以1~n这n个数 ...
- Codeforces 724 G Xor-matic Number of the Graph 线性基+DFS
G. Xor-matic Number of the Graph http://codeforces.com/problemset/problem/724/G 题意:给你一张无向图.定义一个无序三元组 ...
- Codeforces G. Bus Number(dfs排列)
题目描述: Bus Number time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- G - Harmonic Number (II) LightOJ - 1245
算是一个找规律的题目吧. 枚举前sqrt(n)个数,数i出现的次数为n/i-n/(i+1),对答案的贡献为(n/i-n/(i+1))*i. 对于sqrt后边的数,可以直接由n/i获得,并且一定只出现一 ...
- LightOJ 1245 Harmonic Number (II)(找规律)
http://lightoj.com/volume_showproblem.php?problem=1245 G - Harmonic Number (II) Time Limit:3000MS ...
- 华中农业大学第五届程序设计大赛网络同步赛-G
G. Sequence Number In Linear algebra, we have learned the definition of inversion number: Assuming A ...
- hzau 1205 Sequence Number(二分)
G. Sequence Number In Linear algebra, we have learned the definition of inversion number: Assuming A ...
- input属性设置type="number"之后, 仍可输入e, E, -, + 的解决办法
<el-input v-model="scope.row.variables.leaderbuweiscores.score" @keyup.native="cha ...
随机推荐
- sap人员编制
[转]中小SAP项目中的人员编制 转自http://w39.itpub.net/post/24/398817 对于SAP项目来说,常有人把项目所需的人员说的很多--每个模块一个内部顾问和一个开发的 ...
- linux source命令与sh shell scripts的区别
source FileName 作用:在当前bash环境下读取并执行FileName中的命令. 注:该命令通常用命令“.”来替代. 如:source .bash_rc 与 . .bash_rc 是等效 ...
- Java GET和POST请求
从表面来看GET和POST请求: GET请求是在url后直接附上请求体,url和请求体之间用"?"分割,不同参数之间用"&"分隔,%XX中的XX为该符号 ...
- 网络测试常用的命令-比较ping,tracert和pathping等命令之间的关系
无论你是一个网络维护人员,还是正在学习TCP/IP协议,了解和掌握一些常用的网络测试命令将会有助于您更快地检测到网络故障所在,同时也会有助你您了解网络通信的内幕. 下面我们逐步介绍几个常用的命令: 1 ...
- [原创]Java开发如何在线打开Word文件
此方案使用了PageOffice产品实现在线打开Word文档: 1. 首先从PageOffice官网下载产品开发包,http://www.zhuozhengsoft.com/dowm/ ,下载Page ...
- DDD领域驱动之干货 (一)
说道DDD不得不说传统的架构与DDD的架构区别. 传统的架构不外乎就是三层,而在这三层里面又不断的细分,始终没有达到想要的效果,那么为什么当时还是采用三层. 当然在DDD没有提出的时候三层是大多数人的 ...
- codevs 1048石子归并
传送门 1048 石子归并 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 有n堆石子排成一列,每堆石子有一个重量w[i], ...
- oracle获取一段时间内所有的小时、天、月
获取一段时间内所有的小时 ) sdate FROM dual CONNECT ; 获取一段时间内所有的天 sdate FROM dual CONNECT ; from user_objects whe ...
- JavaScript-Tool-导向:jquery.steps-un
ylbtech-JavaScript-Tool-导向:jquery.steps 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 0. http://www.jqu ...
- 【旧文章搬运】为什么win32k.sys在System进程空间无法访问
原文发表于百度空间,2010-01-02========================================================================== 玩过Sha ...