【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 ...
随机推荐
- while循环语句
while(循环条件,返回布尔类型) { 代码执行的操作,或者打印输出. } do whilw循环 do { ...
- ###《Effective STL》--Chapter5
点击查看Evernote原文. #@author: gr #@date: 2014-09-17 #@email: forgerui@gmail.com Chapter5 算法 Topic 30: 确保 ...
- 12天学好C语言——记录我的C语言学习之路(Day 1)
12天学好C语言--记录我的C语言学习之路 Day 1: 刚刚入门C语言,那么肯定要先把什么是C语言和大家讲清楚,那么大家看下面一段程序(program 1.1): /*//program 1.1 ...
- Web前端新人笔记之文本属性
前一段时间因工作时间减缓了更新笔记的时间.我也不知道有没有会观看并且能不能帮到一些初学者,这只是我的一些小随笔而已.当然我也希望的的每一篇随笔都可以帮到更多的想要学习前端开发的初学者们,更希望你们也可 ...
- ajax提交数据Demo
$.ajax({ url: "url", type: "post", data: JSON.stringify(yourData), contentType: ...
- python 数据类型(列表)学习笔记
列表 创建列表: name_list = ['alex', 'seven', 'eric'] 或 name_list = list(['alex', 'seven', 'eric']) 其实今天学习的 ...
- poj 2796 Feel Good 单调栈区间问题
Feel Good 题意:给你一个非负整数数组,定义某个区间的参考值为:区间所有元素的和*区间最小元素.求该数组中的最大参考值以及对应的区间. 比如说有6个数3 1 6 4 5 2 最大参考值为6,4 ...
- PL/SQL — BULK COLLECT用法
BULK COLLECT 子句会批量检索结果,即一次性将结果集绑定到一个集合变量中,并从SQL引擎发送到PL/SQL引擎.通常可以在SELECT INTO.FETCH INTO以及RETURNING ...
- windows下使用MinGW的调试工具gdb.exe调试C程序
1.编译源代码 C:MinGW\bin>gcc.exe -g -o program.exe program.c 编译选项上要加上“g”,这样生成的目标程序会含有调试内容,再用gdb调试的时候才能 ...
- 中国.net域名网站的“前世今生”,那些年的光辉
1987年9月的一天,中国的第一封电子邮件成功发出,邮件的内容大致是“跨越长城,走向世界”,在当时,没有人会想到十年后中国的互联网开始萌芽,并发展成今天的繁荣.1994年,“巴黎统筹委员会”的解散消除 ...