hdu3652B-number
100
200
1000
1
2
2
题解:
设f[i][j][r][0/1]表示i位数(可含前导0)第一位为j,mod13的余数是r,有没有出现13(0/1)的数有几个
code:
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxl=;
const int maxnum=;
const int rest=;
int n,power[maxl],f[maxl][maxnum][rest][],a[maxl];
void init(){
power[]=;
for (int i=;i<=;i++) power[i]=power[i-]*%;
f[][][][]=;
for (int i=;i<=;i++) for (int j=;j<=;j++)
for (int k=;k<=;k++) for (int r=;r<;r++){
int tmp=(r+j*power[i])%;
if (!(j==&&k==)) f[i][j][tmp][]+=f[i-][k][r][];
else f[i][j][tmp][]+=f[i-][k][r][];
f[i][j][tmp][]+=f[i-][k][r][];
}
}
int calc(int n){
int ans=,t=n,len=,r=,tmp;
bool flag=;
memset(a,,sizeof(a));
while (t) a[++len]=t%,t/=;
for (int i=len;i;i--){
for (int j=;j<a[i];j++){
tmp=((-(r+j*power[i]))%+)%;
for (int k=;k<=;k++) ans+=f[i-][k][tmp][];
if (!flag){
if (a[i+]==){if (j==) for (int k=;k<=;k++) ans+=f[i-][k][tmp][];}
if (j==) ans+=f[i-][][tmp][];
}
else for (int k=;k<=;k++) ans+=f[i-][k][tmp][];
}
r+=a[i]*power[i],r%=;
if (a[i+]==&&a[i]==) flag=;
}
return ans;
}
int main(){
init();
while (~scanf("%d",&n)) printf("%d\n",calc(n+));
return ;
}
hdu3652B-number的更多相关文章
- JavaScript Math和Number对象
目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- 移除HTML5 input在type="number"时的上下小箭头
/*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...
- iOS---The maximum number of apps for free development profiles has been reached.
真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- [LeetCode] Number of Boomerangs 回旋镖的数量
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- [LeetCode] Number of Segments in a String 字符串中的分段数量
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...
随机推荐
- 用函数生成select选择框
// 生成 html select option 标签 function build_options($options, $opt='',$k='') { $frags = array(); if ( ...
- 【设计模式 - 4】之原型模式(Prototype)
1 模式简介 原型模式的定义:通过复制一个现有的对象(原型)来得到一个相似的对象. 原型模式的UML图如下图所示: 从上图中可以看到,所有的对象实体类都是继承自一个Prototype的父类, ...
- 【设计模式 - 6】之桥接模式(Bridge)
1 模式简介 举个例子,人.车和公路是三个维度,人开着车在公路上行驶,就是将这三个维度进行了关联.人分男人(Man)和女人(Woman),车分小轿车(Car)和公共汽车(Bus),公路分市区 ...
- 京东手机webapp商城
http://bases.wanggou.com/mcoss/mportal/show?tabid=2&ptype=1&actid=1562&tpl=3&pi=1&am ...
- Linux下配置SSL (转)
没有安装apache的情况: 首先安装SSL,再编译安装Apache,再配置证书即可 1.下载apache和openssl 网址:http://www.apache.org http://www.op ...
- Systemtap kernel.trace("*") events source code
http://blog.163.com/digoal@126/blog/static/16387704020131014562216/
- Scope Chain(作用域链)
本章,我们讨论一下ECMAScript中的作用域链 , 开门见山. 什么是作用域链 i.ECMAScript是允许创建内部函数的,甚至能从父函数中返回这些函数.作用域链正是内部上下文中所有变量对象(及 ...
- Java——(九)IO流
一.流的分类 1.输入流和输出流 按照流的流向来分,可以分为输入流和输出流 输入流:只能从中读取数据,而不能向其写入数据. 输出流:只能向其写入数据,而不能从中读取数据. 此处的输入.输出涉及一个方向 ...
- 如何使用node中的buffer
介绍:Buffer类是一个全局类,是一个比较罕见不需要require( ‘buffer’ )就可以使用的类,Buffer类似与数组也有length, 它里面的元素为16进制的两位数,即 0-255的数 ...
- Android Cursor类的概念和用法
http://www.2cto.com/kf/201109/103163.html 关于 Cursor 在你理解和使用 Android Cursor 的时候你必须先知道关于 Cursor 的几件事情: ...