hdu3886(数位dp)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3886
题意:给一定区间[A,B],一串由/,\,-组成的符号串。求满足符号串的数字个数。
- #include <cstdio>
- #include <cstring>
- #include <string>
- #include <cmath>
- #include <iostream>
- #include <algorithm>
- #include <queue>
- #include <cstdlib>
- #include <stack>
- #include <vector>
- #include <set>
- #include <map>
- #define LL long long
- #define mod 100000000
- #define inf 0x3f3f3f3f
- #define N 100010
- #define FILL(a,b) (memset(a,b,sizeof(a)))
- #define lson l,m,rt<<1
- #define rson m+1,r,rt<<1|1
- using namespace std;
- int dp[][][];
- int dig[],len;
- char str[],a[],b[];
- int judge(int i,int pre,int now)
- {
- if(str[i]=='/')return pre<now;
- else if(str[i]=='-')return pre==now;
- else if(str[i]=='\\')return pre>now;
- }
- int dfs(int pos,int cur,int pre,int limit,int fzore)
- {
- if(!pos)return cur==len;
- if(!limit&&~dp[pos][cur][pre])return dp[pos][cur][pre];
- int ed=limit?dig[pos]:;
- int ans=;
- for(int i=;i<=ed;i++)
- {
- if(!fzore)
- {
- if(cur<len&&judge(cur,pre,i))
- ans+=dfs(pos-,cur+,i,limit&&i==ed,fzore&&!i);
- //这里为什么能往回走,因为如果pre,i满足str[cur-1],同时
- //已经知道“pre前一位,pre”也满足str[cur-1],这样还是满足要求的数
- //例如数据123455555554321是符合/-\的,5之前都是/,中间都是-,后面都是\。
- else if(cur&&judge(cur-,pre,i))
- ans+=dfs(pos-,cur,i,limit&&i==ed,fzore&&!i);
- }
- else ans+=dfs(pos-,cur,i,limit&&i==ed,fzore&&!i);
- ans%=mod;
- }
- if(!limit)dp[pos][cur][pre]=ans;
- return ans;
- }
- int solve(char s[],bool left)
- {
- int lens=strlen(s),m=,i=;
- while(s[i]==''&&i<lens)i++;
- for(int j=lens-;j>=i;j--)dig[++m]=s[j]-'';
- if(left&&m)
- {
- for(int i=;i<=m;i++)
- {
- if(dig[i])
- {
- dig[i]--;break;
- }
- else dig[i]=;
- }
- }
- return dfs(m,,,,);
- }
- int main()
- {
- while(scanf("%s",str)!=EOF)
- {
- len=strlen(str);
- scanf("%s%s",a,b);
- memset(dp,-,sizeof(dp));
- printf("%08d\n",((solve(b,)-solve(a,))+mod)%mod);
- }
- }
hdu3886(数位dp)的更多相关文章
- [转]数位dp小记
转载自:http://blog.csdn.net/guognib/article/details/25472879 参考: http://www.cnblogs.com/jffifa/archive/ ...
- 数位DP 计划
通常的数位dp可以写成如下形式: [cpp] view plain copy int dfs(int i, int s, bool e) { if (i==-1) return s==target_s ...
- 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
- bzoj1026数位dp
基础的数位dp 但是ce了一发,(abs难道不是cmath里的吗?改成bits/stdc++.h就过了) #include <bits/stdc++.h> using namespace ...
- uva12063数位dp
辣鸡军训毁我青春!!! 因为在军训,导致很长时间都只能看书yy题目,而不能溜到机房鏼题 于是在猫大的帮助下我发现这道习题是数位dp 然后想起之前讲dp的时候一直在补作业所以没怎么写,然后就试了试 果然 ...
- HDU2089 不要62[数位DP]
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 数位DP GYM 100827 E Hill Number
题目链接 题意:判断小于n的数字中,数位从高到低成上升再下降的趋势的数字的个数 分析:简单的数位DP,保存前一位的数字,注意临界点的处理,都是套路. #include <bits/stdc++. ...
- 数位dp总结
由简单到稍微难点. 从网上搜了10到数位dp的题目,有几道还是很难想到的,前几道基本都是模板题,供入门用. 点开即可看题解. hdu3555 Bomb hdu3652 B-number hdu2089 ...
- 数位DP入门
HDU 2089 不要62 DESC: 问l, r范围内的没有4和相邻62的数有多少个. #include <stdio.h> #include <string.h> #inc ...
- 数位DP之奥义
恩是的没错数位DP的奥义就是一个简练的dfs模板 int dfs(int position, int condition, bool boundary) { ) return (condition ? ...
随机推荐
- java按值传递理解(转)
ava没有引用传递只有按值传递,没有引用传递只有按值传递,值传递. 通过下面代码解释: 1 public class Test { 2 public static void main(String[] ...
- 零基础数据分析与挖掘R语言实战课程(R语言)
随着大数据在各行业的落地生根和蓬勃发展,能从数据中挖金子的数据分析人员越来越宝贝,于是很多的程序员都想转行到数据分析, 挖掘技术哪家强?当然是R语言了,R语言的火热程度,从TIOBE上编程语言排名情况 ...
- Windows Azure 安全最佳实践 - 第 4 部分:需要采取的其他措施
那么,哪些安全威胁应由WindowsAzure环境缓解?哪些安全威胁必须由开发人员缓解? 开发 Windows Azure 应用程序的最佳安全做法一文说明了对于在 Windows Azure 中运行的 ...
- 基于visual Studio2013解决C语言竞赛题之1052求根
题目 解决代码及点评 /* 功能:用简单迭代法解方程 e^x - x - 2 = 0 它有两个根(如图),其迭代公式为: 1) x[n+1]= e^x*n-2 (初值X<0时) ...
- FZOJ2111:Min Number
Problem Description Now you are given one non-negative integer n in 10-base notation, it will only c ...
- mysql 执行计划走索引
<pre name="code" class="html">mysql> desc AssignClientManager; +------- ...
- OCX控件在IE中无法侦测到键盘消息( MFC ActiveX Control in IE Doesn't Detect Keystrokes)
症状描述: Accelerator keys, such as ARROW keys, are first received by the message pump of the ActiveX co ...
- BZOJ 3211 弗洛拉前往国家 树阵+并检查集合
标题效果:给定一个序列,它提供了以下操作: 1.将[l.r]每个号码间隔a[i]变sqrt(a[i]) 2.查询[l,r]间隔和 剧烈的变化不支持由间隔,因此,我们选择单 - 点更换间隔查询的树阵,但 ...
- 2013Esri全球用户大会之ArcGIS for Desktop
Q1:ArcGIS 10.2 for Desktop中有哪些新特性? 增强的质量和性能 扩展并行处理能力 许多软件质量的改进 优化的文件处理 ...
- 玩转Windows服务系列——Windows服务小技巧
原文:玩转Windows服务系列——Windows服务小技巧 伴随着研究Windows服务,逐渐掌握了一些小技巧,现在与大家分享一下. 将Windows服务转变为控制台程序 由于默认的Windows服 ...