【HDOJ】3652 B-number
终于自己写出来一道数位DP啊。继续训练DP。
/* 3652 */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxl = ;
int dp[maxl][][][];
char s[]; void solve() {
int len = strlen(s); rep(i, , len)
s[i] -= ''; memset(dp, , sizeof(dp));
dp[][][][] = ; rep(i, , len) {
rep(j, , ) {
rep(k, , ) {
if (!dp[i][][j][k])
continue;
int dtmp = (i==) ? s[i]+:;
rep(d, , dtmp) {
int jj = (j* + d)%;
int kk = ;
int p = ; if (k == ) {
kk = ;
} else if (k == ) {
if (d == ) {
kk = ;
} else if (d == ) {
kk = ;
}
} else {
if (d == ) {
kk = ;
}
} if (i== && d==s[i])
p = ; dp[i+][p][jj][kk] += dp[i][][j][k];
}
}
} rep(j, , ) {
rep(k, , ) {
if (!dp[i][][j][k])
continue;
rep(d, , s[i]+) {
int jj = (j* + d)%;
int kk = ;
int p = ; if (k == ) {
kk = ;
} else if (k == ) {
if (d == ) {
kk = ;
} else if (d == ) {
kk = ;
}
} else {
if (d == ) {
kk = ;
}
} if (d == s[i])
p = ; dp[i+][p][jj][kk] += dp[i][][j][k];
}
}
}
} int ans = dp[len][][][];
printf("%d\n", ans);
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int x; while (scanf("%d", &x)!=EOF) {
++x;
sprintf(s, "%d", x);
solve();
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}
【HDOJ】3652 B-number的更多相关文章
- 【HDOJ】3948 The Number of Palindromes
后缀数组求不重复回文子串数目.注意dp数组. /* 3948 */ #include <iostream> #include <sstream> #include <st ...
- 【HDOJ】4162 Shape Number
循环串的最小表示法. /* */ #include <iostream> #include <string> #include <map> #include < ...
- 【HDOJ】1018 Big Number
数学题,还是使用log避免大数,但是不要忘记需要+1,因为0也是1位,log(100)= 2,但却是3位. #include <stdio.h> #include <math.h&g ...
- 【HDOJ】3006 The Number of set
数据量这么小,果断状态压缩+dp. /* 3006 */ #include <iostream> #include <string> #include <map> ...
- 【HDOJ】5179 beautiful number
DFS. /* 5179 */ #include <iostream> #include <algorithm> #include <map> #include & ...
- 【转】oracle数据库NUMBER数据类型
原文:http://www.jb51.net/article/37633.htm NUMBER ( precision, scale)a) precision表示数字中的有效位;如果没有指定prec ...
- 【CF245H】Queries for Number of Palindromes(回文树)
[CF245H]Queries for Number of Palindromes(回文树) 题面 洛谷 题解 回文树,很类似原来一道后缀自动机的题目 后缀自动机那道题 看到\(n\)的范围很小,但是 ...
- 【BZOJ4026】dC Loves Number Theory 分解质因数+主席树
[BZOJ4026]dC Loves Number Theory Description dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯竭的水题资源. 给 ...
- 【LeetCode】375. Guess Number Higher or Lower II 解题报告(Python)
[LeetCode]375. Guess Number Higher or Lower II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...
随机推荐
- 【html】【11】函数名称约束规范
一.匈牙利命名法: [不推荐]基本原则是:变量名=属性+类型+对象描述,其中每一对象的名称都要求有明确含义,可以取对象名字全称或名字的一部分.要基于容易记忆容易理解的原则.保证名字的连贯性是非常重要的 ...
- 11_Servlet基础知识
[概念] Servlet通常被称为服务端小程序,是运行在服务端的程序,用于处理及相应客户端的请求. Servlet是用java语言开发网页动态资源的技术. [特点] 1.Servlet是个特殊的Jav ...
- InstallShield: Component-Feature Associations
Quote from: http://helpnet.installshield.com/installshield16helplib/IHelpFeatAssociateComponents.htm ...
- ThreadPoolExecutor 线程池的实现
ThreadPoolExecutor继承自 AbstractExecutorService.AbstractExecutorService实现了 ExecutorService 接口. 顾名思义,线程 ...
- CentOS 7 install LNMP
CentOS 7 install LNMP 关于 Nginx (发音 “engine x”)这是一款免费.开源.高效的 HTTP 服务器,Nginx是以稳定著称,丰富的功能,结构简单,低资源消耗.本教 ...
- jQuery 中的防冲突(noConflict)机制
许多的 JS 框架类库都选择使用 $ 符号作为函数或变量名,jQuery 是其中最为典型的一个.在 jQuery 中,$ 符号只是 window.jQuery 对象的一个引用,因此即使 $ 被删除,w ...
- win7下 mysql主从配置实现
win7下学习 mysql主从复制 一.环境: 主服务器(master):192.168.1.23 mysql版本:5.5 从服务器(slave):192.168.1.24 mysql版本:5.5 ...
- 一台Ubuntu server上安装多实例MySQL
受环境所迫,在一台Ubuntu server上安装多个实例MySQL. 手动安装MySQL 环境:Ubuntu server 11.10 64bit + mysql-5.5.17-linux2.6-x ...
- platform平台设备驱动简化示例代码
driver.c: #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h& ...
- find grep
grep grep -rn "hello,world!" * #递归查找当前目录下所有包含hello,world的文件 grep -C number pattern files : ...