B-number
B-number
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3652
数位dp
这题是暑期集训的时候做的,昨天补了数位dp的记忆化搜索做法,把艾神的递推算法更新一下。
代码如下:
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#define LL long long
#define LEN 20
#define is_1 2
#define have_13 2
#define mod_by_13 13
#define pre_same 2
using namespace std;
LL t[LEN];
LL dp[LEN][is_1][have_13][mod_by_13][pre_same];
string s;
LL len;
void init_t();
void solve();
int main(void){
init_t();
while(cin>>s){
len=s.size();
memset(dp,,sizeof(dp));
dp[][][][][]=;
solve();
LL temp=;
for(int i=;i<is_1;++i)
for(int j=;j<pre_same;++j)
temp+=dp[len][i][][][j];
cout<<temp<<endl;
}
}
void init_t(){
t[]=;
for(int i=;i<LEN;++i)
t[i]=(t[i-]*)%;
}
void solve(){
for(int a=;a<len;++a)
for(int b=;b<is_1;++b)
for(int c=;c<have_13;++c)
for(int d=;d<mod_by_13;++d)
for(int e=;e<pre_same;++e)
if(dp[a][b][c][d][e]){
int r=(e?s[a]-'':);
for(int x=;x<=r;++x){
dp[a+][x==][c|(b&&x==)][(d+t[len-a-]*x)%][e&&x==r]
+=dp[a][b][c][d][e];
}
}
}
感觉还是太懒了,这两周金工实习这么好的机会,居然每天也只能写一道题,而且是水题。
B-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 ...
随机推荐
- javascript构造函数以及原型对象的理解
以下是一个构造函数的例子 如果是实例方法,不同的实例化,它们引用的地址是不一样的,是唯一的. //定义一个构造函数 function People(name,age){ this.name=name; ...
- iOS开发-OC语言 (一)oc数据类型
分享一套以前学习iOS开发时学习整理的资料,后面整套持续更新: oc数据类型 数据类型:基本数据类型.指针数据类型 基本数据类型:数值型.字符型(char).布尔型.空类型(void) 指针数据类型: ...
- 线段树练习 3&&P3372 【模板】线段树 1
题目描述 Description 给你N个数,有两种操作: 1:给区间[a,b]的所有数增加X 2:询问区间[a,b]的数的和. 输入描述 Input Description 第一行一个正整数n,接下 ...
- C语言:SQLITE3的学习
Sqlite基础学习 一.sqlite的概念 SQLite是一款轻型数据库,是遵守ACID的关系型数据库管理系统,由C语言开发设计.Sqlite的设计目标着眼于嵌入式领域,所以具有占用系统资源低和处理 ...
- Noip 2016
Day1 思路: 大致是 把一个环拆成链, 找某个人无非是向右找或向左找(即对当前点加或减) 若加上要移动的位置后坐标大于总人数, 就把当前坐标减去总人数, 若减去要移动的位置后坐标小于0, 就把当前 ...
- Socket编程中的长连接、短链接以及心跳包机制详解
参考:http://blog.csdn.net/zdwzzu2006/article/details/7723738 一.定义 1.TCP连接 当网络通信时采用TCP协议时,在真正的读写操作之前,se ...
- webservices(一)
---完全摘自网络 什么是webService WebService,顾名思义就是基于Web的服务.它使用Web(HTTP)方式,接收和响应外部系统的某种请求.从而实现远程调用. 1:从WebSer ...
- C#基础--属性
定义一个Book类: namespace ConsoleTest { public class Book { private string _bookIsbn; private string _boo ...
- HC-05与HC-06的AT指令的区别
蓝牙HC-05与HC-06对比指令集 高电平->AT命令响应工作状态 低电平->蓝牙常规工作状态 <重新上电表示完成复位> HC-05 可以主从切换模式,但是HC-06 ...
- mysql中timestamp的自动生成与更新
转自:mysql中timestamp的自动生成与更新 MYSQL中TIMESTAMP类型可以设定默认值,就像其他类型一样.1.自动UPDATE 和INSERT 到当前的时间:表:----------- ...